node-cron syntax
A node-cron expression has five fields, or six when you add seconds at the start. With five fields the job runs at second 0:
| Field | Allowed values | Special characters |
|---|---|---|
| Second | 0–59 (optional, comes first) | , - * / |
| Minute | 0–59 | , - * / |
| Hour | 0–23 | , - * / |
| Day of month | 1–31 | , - * ? / L W |
| Month | 1–12 or names (JAN, January) | , - * / |
| Day of week | 0–7 or names (0 and 7 = Sunday) | , - * ? / L # |
Special characters
| Symbol | Meaning |
|---|---|
/ | Steps, written after * or a range: */10 or 5-59/15. A bare start value such as 5/15 is rejected. |
- | Ranges. Since 4.6 a reversed range wraps around, so 22-2 in the hour field runs from 22:00 to 02:59; older versions quietly swap it to 2-22. |
L | In day-of-month, L is the last day of the month (4.3+) and L-3 three days before it (4.6+). In day-of-week, 5L is the last Friday of the month (4.5+). |
W | The weekday nearest to a date: 15W, or LW for the last weekday of the month (4.6+). |
# | The nth weekday of the month: 1#1 is the first Monday (4.5+). |
? | Same as *, accepted in the day fields so that Quartz-style expressions parse (4.6+). |
node-cron cron examples
Click an expression to load it into the generator above.
| Expression | Schedule |
|---|---|
| Every second. | |
| Every 10 seconds. | |
| Every 5 minutes. | |
| At 8:30 AM, Monday through Friday. | |
| At 9:00 AM, Monday through Friday. | |
| Every 15 minutes, between 10:00 PM and 2:59 AM. | |
| At 12:00 AM, on the last day of the month. | |
| At 9:00 AM, 3 days before the last day of the month. | |
| At 9:00 AM, on the first Monday of the month. | |
| At 5:00 PM, on the last Friday of the month. | |
| At 12:00 AM, on day 13 of the month, but only if that day is a Friday. | |
| At 12:00 AM. |
How node-cron differs from Linux crontab
- An optional seconds field comes first, so
*/10 * * * * *runs every 10 seconds. Crontab has no seconds at all. - If you set both a day of month and a day of week, both must match:
0 0 13 * 5runs only on Friday the 13th, while crontab runs it on every 13th and every Friday. - The
L,Wand#characters come from Quartz, but the numbering does not:1is Monday, as in crontab, and both day fields can be set at once. - Jobs run inside your Node.js process. Nothing fires while it is stopped, and every instance of your app fires its own copy unless you set
distributed: true(4.4+). - Without the
timezoneoption, schedules follow the time zone of the Node.js process, which is often UTC on servers and in containers.
Use it in Node.js
Schedule a function with cron.schedule(). In node-cron 4 the task starts right away, and the options set the time zone and skip a run while the last one is still busy:
import cron from 'node-cron';
const task = cron.schedule('0 30 8 * * 1-5', async () => {
await sendDailyReport();
}, {
name: 'daily-report',
timezone: 'Asia/Riyadh',
noOverlap: true,
});
cron.validate('0 30 8 * * 1-5'); // true
task.getNextRuns(3); // the next three run dates (4.4+)
node-cron 3 reads some expressions differently: its steps keep only values divisible by the step, so 5-59/15 fires at :15, :30 and :45 rather than :05, :20, :35 and :50. Run npm ls node-cron to see which version you have.
Frequently asked questions
How do I run a node-cron job every 10 seconds?
Add a seconds field at the start: cron.schedule('*/10 * * * * *', task). With five fields node-cron runs at second 0, so * * * * * fires once a minute.
Which node-cron version supports L, W and #?
L in day-of-month arrived in 4.3, # and 5L in 4.5, and W, L-n and ? in 4.6, which also made reversed ranges such as 22-2 wrap around. node-cron 3 has none of them. The generator warns when an expression needs a newer version.
How do I set the time zone in node-cron?
Pass an IANA name in the options: cron.schedule('0 8 * * *', task, { timezone: 'Asia/Dubai' }). Without it, node-cron uses the time zone of the Node.js process.
Do these expressions work in other JavaScript cron libraries?
Most Node.js schedulers, such as the cron package and Croner, share the five- and six-field layout, but details differ, including how the two day fields combine and which special characters work. Test the expression with the library you use; this generator follows node-cron.
Cron generators for other platforms
*/15 8-18 * * 1-5
Quartz Cron Expression Generator
0 0 8 ? * MON-FRI
Spring Cron Expression Generator
0 0 8 * * MON-FRI
AWS Cron Expression Generator
0 8 ? * MON-FRI *
Jenkins Cron Expression Generator
H 2 * * 1-5
Salesforce Cron Expression Generator
0 0 8 ? * MON-FRI
Hangfire Cron Expression Generator
0 8 * * 1-5
Airflow Cron Expression Generator
0 6 * * 1-5