node-cron - Node.js cron syntax & examples
At 04:30, every day.
Next runs · UTC
- —
- —
- —
- —
- —
Calendar
September 2026 · UTC
0 runs
About this tool
node-cron is the most-installed cron library on npm - a light wrapper that schedules JavaScript callbacks on cron-style expressions. It supports 5- and 6-field cron syntax, IANA timezones, and start/stop control. It does not support the L / W / # modifiers - for those, use a Quartz-flavoured library or a runtime check.new Date().getDate() vs the last day of the month - same pattern as the robfig/cron approach.Basic node-cron usage
import cron from 'node-cron';
// Every weekday at 09:00 New York time
cron.schedule(
'0 9 * * 1-5',
() => {
console.log('Tick');
},
{ timezone: 'America/New_York' }
);Sub-minute with the seconds field
// Every 30 seconds (6-field with seconds at the front)
cron.schedule('*/30 * * * * *', () => {
console.log('Half-minute tick');
});The 6-field syntax with seconds works in node-cron, but not in standard 5-field cron. Pin to 5-field if you need to port the schedule to other systems.
Pausing and resuming a task
const task = cron.schedule('*/5 * * * *', () => {
pollExternalApi();
});
// Pause during a maintenance window
task.stop();
// Resume after maintenance
task.start();
// Tear down completely
task.destroy();Validating an expression before scheduling
if (!cron.validate(userProvidedExpression)) {
throw new Error(`Invalid cron expression: ${userProvidedExpression}`);
}
cron.schedule(userProvidedExpression, runUserJob);Use cron.validate when accepting cron expressions from users - invalid input causes node-cron to throw at scheduling time, which is harder to handle than a proactive validation step.
node-cron pitfalls
- No L / W / # / ? - for last-day-of-month use a runtime check or a different library.
- Process-bound - when the Node process exits, the schedule stops. For durable scheduling use a queue (BullMQ, Agenda) or a system cron.
- Single-process - if you horizontally scale your Node app, every replica will fire the cron. Add a leader-election layer or move the schedule to one singleton instance.
- Long callbacks - node-cron does not serialize concurrent runs. Wrap with a mutex or use
maxConcurrencyoptions from a queue library.
Examples
- 0 18 * * *Every day at 18:00
- 0 */5 * * *Every 5 hours
- 0 18 * * 1-5Weekdays at 18:00
- 0 0 1 * *Once a month, on the 1st at midnight
Cheatsheet
Full cheatsheet| Field | Req. | Range | Wildcards |
|---|---|---|---|
| minute | yes | 0-59 | , - * / |
| hour | yes | 0-23 | , - * / |
| day of month | yes | 1-31 | , - * / |
| month | yes | 1-12 or JAN-DEC | , - * / |
| day of week | yes | 0-6 or names; some dialects use 0-7 or 1-7 — see Dialects | , - * / |
Frequently asked questions
Syntax
What cron syntax does node-cron support?
node-cron accepts 5- or 6-field cron expressions, with optional seconds first. It supports standard wildcards plus L, L-n, W, LW, #, and ? in their documented day-field positions.
Where does the optional seconds field go in node-cron?
The optional seconds field goes first. */30 * * * * * runs every 30 seconds, while * * * * * uses the standard five-field form and runs every minute. Expression: */30 * * * * *
Can node-cron use month and weekday names?
Yes. node-cron accepts names such as JAN, SEP, MON, and FRI in the month and day-of-week fields, including ranges such as MON-FRI.
Timing
How do I run node-cron every five minutes?
Use */5 * * * *. It fires on clock-aligned minute values 0, 5, 10, and so on, rather than five minutes after the previous callback finishes. Expression: */5 * * * *
Days and months
How does node-cron combine day-of-month and day-of-week restrictions?
node-cron uses AND semantics when both day fields are restricted, so both conditions must match. This differs from Vixie cron, which uses OR semantics in that case.
Can recent node-cron versions schedule the last day of a month?
Yes. Recent node-cron versions support L in the day-of-month field, so 0 0 L * * means midnight on the last calendar day of each month. Check your installed version before relying on extended operators.
Timezones and DST
How do I set a timezone with node-cron?
Pass { timezone: 'America/New_York' } (or any IANA timezone) as the third argument to cron.schedule. Without it, node-cron uses the Node.js process timezone (typically the host's local time).
How does daylight saving time affect a node-cron schedule?
node-cron can skip a nonexistent local time during spring-forward. During fall-back, it fires at the first matching wall time and ignores the repeated occurrence.
Platforms
What's the difference between node-cron and cron, croner, cron-parser?
node-cron is an in-process scheduler with optional seconds and documented day modifiers. cron and croner are alternative schedulers with different APIs and dialects, while cron-parser parses expressions without scheduling jobs.
What happens when node-cron runs in multiple app replicas?
Each replica registers and fires its own task. Use a single scheduler process, leader election, or a distributed lock when only one execution should occur.
Does node-cron persist schedules across process restarts?
No. node-cron is an in-process scheduler, so tasks exist only while the Node.js process is running and must be registered again after every restart.
Debugging
How do I stop and restart a node-cron task?
cron.schedule() starts automatically and returns a task with .stop() and .start() methods. Use cron.createTask() when you need a task that is stopped when created.
How do I validate a node-cron expression before scheduling it?
Call cron.validate(expression). It returns a boolean, letting you reject malformed user input before cron.schedule attempts to register the task.
Can node-cron jobs overlap?
Yes. A new tick can arrive while the previous callback is still running, so protect non-reentrant work with node-cron's concurrency controls or an application-level lock.
Crontap
Can Crontap run a schedule created for node-cron?
Yes. You can run a compatible cron schedule on Crontap when the work is exposed as an HTTP endpoint; verify optional-seconds and extended-operator compatibility before moving it.
Write the cron here. Run it on Crontap.
Point Crontap at any URL. Pick any cron. Done.
WordPress, Shopify, Railway, Cloud Run, Vercel, HubSpot, Ghost, your own box. If it answers HTTP, Crontap can drive it on a clock you can read, in the timezone that actually matters, and page you when something breaks.
1.9k+ teams · Free forever tier · No credit card