Skip to main content

moodle-driver

Full control of Moodle as any user, with their own login: no web services, no tokens, no admin.

No web services, no tokens

Works where web services are off or tokens aren't allowed: the person logs in once, single sign-on and two-factor included, and the driver works with that session. It never handles a password.

Full control as any user

Whatever the person can do: read courses and content, submit and answer as a student, grade, build activities, run forums and the gradebook as a teacher.

Moodle's own services

Calls the AJAX services Moodle's pages call, with the person's session, and fills Moodle's own forms where no service helps, with Moodle's validation.

Any language, any theme

Reads Moodle by ids, data attributes, field names and URLs, never by visible text. Results are plain data with ISO dates.

At a person's pace

Student actions can read and answer page by page at a reader's pace, so Moodle logs views and completion as for a person.

Ready for policies

Every function declares the data it touches: own, course content, others' work, grading, communication. Allow only the kinds you trust.

Log in once, then work the site

The person logs in by hand in a browser window, once; the session stays in a profile on disk. Every operation is a method of the Moodle object, takes ids and options, and returns plain data.

import { createMoodle } from "@falkenslab/moodle-driver";

const moodle = createMoodle({ site: "https://campus.example.org/", profileDir: "/home/me/.moodle-profile", headless: true, downloadBrowser: true });
await moodle.logIn({ timeoutMs: 300_000 }); // a window opens only the first time

const courses = await moodle.listCourses();
const { submissions } = await moodle.assignmentSubmissions(35);
for (const s of submissions.filter((s) => s.needsGrading)) {
await moodle.gradeSubmission(35, s.userId, { grade: "8", feedback: "<p>Good work.</p>" });
}
await moodle.close();