node-schedule
Flexible Node.js scheduler supporting cron expressions, date objects, recurrence rules and one-off timers.
Official Documentation ↗node-schedule v2.x / Node 18 LTS. Check the official docs for the latest API surface.Installation
npm install node-schedulepnpm add node-scheduleyarn add node-scheduleMethods
No methods match this filter.
Overview
node-schedule offers a broader set of triggers than a plain cron string. A job can fire once at a Date, repeatedly on a cron expression, or according to a RecurrenceRule with per-field arrays.
Core Methods
scheduleJob returns a Job handle with cancel and nextInvocation methods. RecurrenceRule models calendars explicitly, which is useful for rules like “every weekend at 09:00” that are awkward as cron strings.
Usage Notes
Name jobs when you need to cancel them later, and store schedules externally if they must survive restarts. Use the handle to reschedule or cancel without scanning a registry.
Common Pitfalls
Jobs execute on the same event loop, so a blocking callback delays other jobs and timer accuracy. Long jobs should be offloaded. Timezone behavior depends on the environment and should be verified for daylight saving changes.
FAQ
- How is node-schedule different from node-cron?
- node-schedule accepts more trigger types, including Date objects and RecurrenceRule with arrays, and can cancel by name. node-cron focuses on crontab expressions and may be simpler for pure cron needs.
- Does it persist jobs across restarts?
- No. Jobs live in memory. Persisting schedules requires storing the rules in a database and re-registering them at startup.
- Can two jobs share a name?
- Names must be unique if you intend to cancel by name, because canceling by name removes the named entry. Give each job a distinct name when you rely on this lookup.
Report a problem with this API docOpens a pre-filled issue on GitHub.