Head terms

node-cron v4 Guide: Syntax, Timezones and Multiple Servers

node-cron v4 explained: cron syntax, timezones and DST, noOverlap, running a job on one instance with distributed: true, and when to switch to a job queue.

Prefer it in screens? See this guide as a Web Story

Quick answer

node-cron is a zero-dependency Node.js library that runs a function on a cron expression inside your running process. Version 4 needs Node.js 20+, starts tasks on creation, takes a timezone option, skips overlapping runs with noOverlap and can run a job on one instance only with distributed: true. It keeps nothing on disk, so missed runs are lost.

node-cron schedules recurring work inside a Node.js process: you pass a cron expression and a function, and the library calls the function at those times. It fits cleanup jobs, cache refreshes, digests and health checks. It is the wrong tool for anything that must survive a restart, because node-cron stores no state and a fire that happens while your process is down never runs.

Most node-cron tutorials still show the v3 API, and several of their options no longer exist. The current line (4.6.0 on npm as of November 2026) is a TypeScript rewrite with new task methods, lifecycle events, overlap prevention and coordination across instances. This guide covers the v4 API, the time zone rules, the multi-instance problem and the point where you should move to a real queue. For the design behind durable scheduling, see our job queue architecture for scheduled posts.

PostGate handles OAuth, publishing and delivery evidence for every network through one API. Start free or read the docs.

01

How do you set up node-cron in Node.js?

Install the node-cron package and call cron.schedule(expression, task, options). The task starts as soon as you create it. v4 ships both ESM and CommonJS builds, so import cron from 'node-cron' and require('node-cron') both work, and it also exposes named exports such as schedule, createTask and validate.

The options object is where most of the v4 features live. timezone takes any IANA name, name labels the task in logs, noOverlap skips a run while the previous one is still running, maxExecutions destroys the task after N runs and maxRandomDelay adds jitter in milliseconds. You can also pass a file path instead of a function, and node-cron runs that file in a forked background process so heavy work does not block your event loop.

node-cron v4: a basic task and a task with optionsPostGate API
// npm install node-cron   (v4 needs Node.js 20 or newer)
import cron from 'node-cron';

// Every 5 minutes, in the server's time zone
cron.schedule('*/5 * * * *', () => {
  console.log('checking the outbox');
});

// Weekdays at 09:00 in New York, whatever time zone the server runs in
const digest = cron.schedule('0 9 * * 1-5', sendDailyDigest, {
  name: 'daily-digest',
  timezone: 'America/New_York',
  noOverlap: true, // skip a run if the previous one is still going
});

digest.on('execution:failed', (ctx) => console.error(ctx.execution?.error));
console.log(digest.getNextRun()); // next fire time as a Date
02

How does the node-cron syntax work?

An expression has five fields (minute, hour, day of month, month, day of week) plus an optional sixth field for seconds at the start. Ranges (1-5), steps (*/15), lists (1,15) and names (mon, jan) all work. v4 also accepts L for the last day of the month, 15W for the nearest weekday and 2#3 for the third Tuesday. Day of month and day of week are combined with AND, which differs from classic Unix cron, so check any expression that sets both. Here are the schedules people search for most:

ScheduleExpression
Every 30 seconds*/30 * * * * * (six fields)
Every minute* * * * *
Every 5 minutes*/5 * * * *
Every hour, on the hour0 * * * *
Every day at midnight0 0 * * *
Weekdays at 09:000 9 * * 1-5
Mondays at 08:3030 8 * * mon
Last day of the month at 18:000 18 L * *

Before you schedule user input, run it through cron.validate(expression), which returns a boolean. That matters when the expression comes from a settings screen rather than your own code.

03

What changed in node-cron v4?

If a tutorial passes scheduled: false or calls task.now(), it was written for v3. The official migration guide lists the breaking changes. The ones that break code most often:

v3v4
Node.js 6 and upNode.js 20 or newer
scheduled: falsecron.createTask(), then task.start()
runOnInit: trueCall task.execute() after scheduling
task.now()task.execute(), which returns a Promise
task-done eventexecution:finished, plus execution:failed, execution:missed and others
recoverMissedExecutionsRemoved. A missed run emits execution:missed and is not replayed
Checked the expression every secondSleeps until the next matching time

New methods also help with monitoring: getStatus(), getNextRun(), lastRun() and destroy(). A health endpoint that reports lastRun() for each named task catches silent failures far sooner than log searches.

04

How do you set a timezone in node-cron?

Pass timezone in the options, for example America/Sao_Paulo or Etc/UTC. Without it, the task uses the system time zone, which is often UTC on a server and something else on your laptop. That mismatch is the most common reason a job "runs at the wrong hour" after deploy. A task with an explicit time zone fires at the same instants no matter where the server runs.

Daylight saving time follows rules worth knowing, per the node-cron timezone docs:

  • Spring forward: a daily time that falls in the skipped hour does not run that day. A job at 30 2 * * * in New York simply skips the transition day.
  • Fall back: a repeated local time fires once, on its first occurrence.
  • If you want fixed spacing all year, use Etc/UTC. The Etc/GMT zones have inverted signs, so Etc/GMT+3 means UTC minus 3.

Pick a region zone when the job should follow local business hours, and UTC when it should run at fixed intervals. When the schedule belongs to a user rather than to your server, store their IANA zone with the schedule. Our guide to how social media schedulers work shows where that zone travels in a real publishing pipeline.

05

Why does node-cron run twice, and how do you stop it?

There are two different causes. The first is overlap: a job that takes longer than its interval starts again before the last run ends. Set noOverlap: true and node-cron skips the new run and emits execution:overlap.

The second is more instances. Two replicas, a PM2 cluster or a blue/green deploy all load the same code, so each one schedules the same job. v4 answers this with distributed: true, documented in distributed coordination. The task then needs a name, and by default reads the NODE_CRON_RUN environment variable: set it to true on exactly one instance and false on the rest. If it is unset, node-cron throws at startup instead of guessing. That default has no failover: if the designated instance is down, the job does not run. For failover, register the Redis coordinator from @node-cron/redis-coordinator (it needs node-cron 4.4.1 or newer), and any instance can win each fire.

The docs are clear that this is coordination, not exactly-once delivery: a crash and retry or large clock skew can still run a fire twice. Make the job idempotent, so a second run finds nothing left to do.

One run per fire across instances, with Redis failoverPostGate API
import { createClient } from 'redis';
import cron, { setRunCoordinator } from 'node-cron';
import { RedisLockCoordinator } from '@node-cron/redis-coordinator';

const redis = createClient();
await redis.connect();

// Any instance can win a fire; only one runs it
setRunCoordinator(new RedisLockCoordinator(redis));

cron.schedule('0 3 * * *', runNightlyCleanup, {
  name: 'nightly-cleanup',     // required: it is the coordination key
  distributed: true,
  distributedLease: 5 * 60_000, // must be longer than the job takes
});
06

node-cron vs BullMQ: when should you move to a job queue?

The node-cron README draws the line itself: for durable queues with retries and priorities, use a queue such as BullMQ, and for exactly-once guarantees across crashes, use a queue or workflow engine. In practice, the split looks like this:

Neednode-cronJob queue (BullMQ, pg-boss)
Recurring job in one processYes, no infrastructureYes, needs Redis or Postgres
One-off job at a set time (next Tuesday 14:00)Not built for it; lost on restartDelayed jobs, stored until due
Survives restarts and deploysNo, state lives in memoryYes
Retries with backoffWrite it yourselfBuilt in
Several instancesdistributed: true (one runner or Redis lock)Workers share the queue
Thousands of user-defined schedulesOne timer per task in memoryRows or keys in the store

A common setup uses both: node-cron (or a queue's own scheduler) fires every minute, and the job looks up rows that are due in your database and pushes them to a queue. If you are picking that queue, our pg-boss vs BullMQ comparison covers the two Node.js options, and BullMQ vs RabbitMQ covers library versus broker.

Scheduled social media posts are the textbook case for the queue side: each post has its own time, users edit it, and the network APIs fail in ways that need retries. If that is the job you were about to write with node-cron, PostGate's schedules API takes a cron expression or daily slots with an IANA time zone and tracks delivery for each platform, so your code makes one API call instead of running the timer.

07

What should you check before running node-cron in production?

  1. Pin a timezone on every task instead of trusting the host.
  2. Give every task a name so logs and lastRun() are readable.
  3. Set noOverlap: true on any job that can run longer than its interval.
  4. Count your instances. More than one means distributed: true or a queue.
  5. Listen to execution:failed and execution:missed and send them to your alerts.
  6. Make each job idempotent, so a duplicate or retried run does no harm.
  7. Bundling with esbuild or webpack? Mark node-cron as external, or background tasks fail to fork.

If a job on that list cannot tolerate a missed run, it belongs in a queue, and node-cron should only be the clock that feeds it.

Frequently asked questions

Is node-cron still maintained?

Yes. Version 4.6.0 was published to npm in July 2026, and the 4.x line added overlap prevention, background tasks and distributed coordination. It has no runtime dependencies and needs Node.js 20 or newer.

Does node-cron run missed jobs after a restart?

No. node-cron keeps its schedule in memory and stores nothing, so a run that falls due while the process is down never happens. v4 also dropped the v3 recoverMissedExecutions option; a late run emits execution:missed instead.

How do I run node-cron every 5 minutes?

Use cron.schedule('*/5 * * * *', task). Add a timezone option if the job must line up with local clock times, and noOverlap: true if a run can take longer than five minutes.

What is the difference between node-cron and BullMQ?

node-cron runs functions on a schedule inside your process and keeps no state. BullMQ is a job queue backed by Redis or PostgreSQL, with delayed jobs, retries and workers spread over many machines. Use node-cron for simple recurring tasks and a queue for jobs that must not be lost.

Build it with PostGate

One API for every social platform your customers care about — sandboxed, documented, and ready today.

Start building Read the docs