PostGate

node-cron v4: syntax, timezones and running on one server

What node-cron does

It runs a function on a cron expression inside your Node.js process. No dependencies, no database. Version 4 needs Node.js 20 or newer.

Missed runs are gone

node-cron keeps its schedule in memory. A run that falls due while the process is down never happens, and v4 does not replay it.

The syntax in five fields

Minute, hour, day of month, month, day of week, plus optional seconds first.
1. Every 5 minutes: */5 * * * *
2. Weekdays at 09:00: 0 9 * * 1-5

v3 tutorials are out of date

scheduled: false is now cron.createTask(). runOnInit and task.now() became task.execute(). The task-done event is now execution:finished.

Always set a timezone

Without the timezone option, the task uses the server's zone, often UTC. Pass an IANA name like America/Sao_Paulo or Etc/UTC.

DST rules

A daily time inside the skipped spring-forward hour does not run that day. On fall-back, a repeated time fires once. Use Etc/UTC for fixed spacing.

Stop overlapping runs

noOverlap: true skips a run while the previous one is still going, and emits execution:overlap.

Two servers, one run

distributed: true plus a name runs each fire on one instance. Set NODE_CRON_RUN to true on one server, or add the Redis coordinator for failover.

When to use a queue

One-off jobs at a set time, retries with backoff and work that must survive a restart belong in a queue like BullMQ or pg-boss.

In the full guide

A v3 to v4 migration table, a node-cron vs job queue comparison and a 7-point checklist before running it in production.

postgate.studio

Read the full guide