node-cron (npm) Cron Syntax
The popular node-cron npm package accepts a standard cron string and also supports an optional leading seconds field, giving six fields. You pass the expression to cron.schedule() with a callback that runs on each tick.
Basic usage
const cron = require('node-cron');cron.schedule('*/5 * * * *', () => { console.log('every 5 min'); });
Optional seconds field
node-cron supports 6 fields when the first is seconds: cron.schedule('*/10 * * * * *', fn) runs every 10 seconds. With 5 fields it behaves like standard cron.
Set a timezone
Pass options: cron.schedule('0 9 * * 1-5', fn, { timezone: 'America/New_York' }). Without it, the server's local time is used.
Validate and control
cron.validate('*/5 * * * *') returns true/false. A scheduled task has .start() and .stop() so you can pause jobs at runtime.
FAQ
Does node-cron support seconds?
Yes — if you provide 6 fields, the first is seconds. '*/10 * * * * *' runs every 10 seconds. With 5 fields it's standard cron.
How do I set a timezone in node-cron?
Pass { timezone: 'America/New_York' } as the third argument to cron.schedule(). Otherwise it uses the server's local time.
How do I stop a node-cron job?
cron.schedule() returns a task object with .start() and .stop() methods, so you can pause and resume it at runtime.