Skip to content

Node-CronJob Scheduling for Node.js

Schedule tasks with cron expressions. Prevent overlaps. Coordinate across instances. Run jobs in background processes. Zero dependencies.

node-cron

From one line to production ​

These docs cover node-cron v4.

node-cron is designed to grow with you. The same schedule call you write on day one is the one you keep; you just add options as your needs grow.

js
import cron from 'node-cron';

// Day one: run something every minute.
cron.schedule('* * * * *', () => {
  console.log('Hello from node-cron');
});

Later, the same task can run in a specific timezone, skip overlapping runs, coordinate across a fleet, and run in its own process:

js
import cron from 'node-cron';

const task = cron.schedule('0 3 * * *', './tasks/nightly-backup.js', {
  name: 'nightly-backup',
  timezone: 'America/Sao_Paulo',
  noOverlap: true,
  distributed: true,
});

task.on('execution:failed', (ctx) => {
  console.error('backup failed:', ctx.execution?.error);
});

When to use node-cron ​

  • Recurring jobs on a schedule (cron expressions with second-level precision)
  • Overlap prevention for long-running tasks
  • Coordinating scheduled tasks across multiple instances or replicas
  • Running heavy jobs in isolated background processes
  • Runtime control: start, stop, inspect, and observe tasks programmatically

Need more than cron?

Check out Sidequest.js, a distributed job runner for Node.js inspired by Oban and Sidekiq. Retries, priorities, schedules, uniqueness, and a web dashboard. Works with Postgres, MySQL, SQLite and MongoDB.

When to consider something else ​

  • Durable job queues with retries and priorities: use Sidequest, BullMQ, or Agenda
  • Persistent workflow orchestration: use Temporal or Inngest
  • Exactly-once guarantees across crashes: node-cron coordinates but does not persist state to a database; a queue or workflow engine is a better fit

Explore the docs ​

Follow the journey in order, or jump straight to what you need:

  1. Quickstart: install and run your first task in five minutes.
  2. Cron Syntax: learn how to express when a task should run.
  3. Task Lifecycle & Status: start, stop, and inspect tasks at runtime.
  4. Scheduling Options: timezones, overlap prevention, limits, and jitter.
  5. Events & Observability: react to every moment in a task's life.
  6. Background Tasks: run jobs in isolated processes.
  7. Distributed Coordination: run a task on one instance per fire across a fleet.
  8. Logging: route node-cron's output through your own logger.
  9. Cookbook: copy-paste recipes for common jobs.

Common problems ​

Released in 2016 under the ISC License.