cronbits
v1.0.0
Published
Cron expression parser, next/previous occurrence finder, and in-process job scheduler for Node.js
Maintainers
Readme
cronbits
Cron expressions for Node.js: parse, validate, find the next/previous run times, describe schedules in plain text, and run an in-process job scheduler.
Zero runtime dependencies. Node 18+.
Install
npm install cronbitsQuick start
import { parse, next, previous, describe, createScheduler } from "cronbits";
parse("*/5 * * * *").matches(new Date()); // every 5 minutes?
next("0 9 * * 1-5", new Date()); // next weekday 09:00
previous("@hourly", new Date()); // previous hour
describe("0 0 1 * *"); // human-readable fields
const scheduler = createScheduler();
scheduler.add("reports", "0 6 * * *", async ({ at }) => {
console.log("daily report", at.toISOString());
});
scheduler.start();Cron syntax
Standard 5-field cron: minute hour day-of-month month day-of-week
- Lists:
1,15 - Ranges:
1-5 - Steps:
*/15,1-10/2 - Names:
JAN,MON - Presets:
@yearly@monthly@weekly@daily@hourly
Scheduler API
| Method | Purpose |
| --- | --- |
| add(name, expr, handler) | Register a job |
| remove / pause / resume | Manage jobs |
| start / stop | Control the timer loop |
| runNow(name) | Fire immediately |
| list() | Snapshot of jobs |
License
MIT
