NPM Star
Collections
  1. Home
  2. Compare
  3. cron vs node-cron
NPM Compare

Compare NPM packages statistics, trends, and features

CollectionsVS Code extensionChrome extensionTermsPrivacyLinkTreeIndiehackersBig Frontendqiuyumi

Unable to load comparison data. Please try again later.

No README available

Node Cron

npm version npm downloads used by coverage zero dependencies license sponsor

Job scheduling for Node.js with overlap prevention, distributed coordination, and background tasks. Schedule recurring tasks with cron expressions, prevent overlapping runs, coordinate across multiple instances, and run heavy jobs in isolated background processes. Zero dependencies, written in TypeScript.

Full documentation: nodecron.com

Getting Started

npm install node-cron
import cron from 'node-cron'; cron.schedule('* * * * *', () => { console.log('running a task every minute'); });

Overlap Prevention

Long-running tasks can overlap when the next tick fires before the previous run finishes. noOverlap skips a run instead of stacking them:

cron.schedule('* * * * *', async () => { await slowJob(); }, { noOverlap: true });

Distributed Coordination

Running multiple instances of your app? distributed: true ensures only one instance executes each scheduled fire. Out of the box it uses an env-var flag; for high availability, plug in a Redis coordinator:

cron.schedule('0 3 * * *', runNightlyBackup, { name: 'nightly-backup', distributed: true, });

Background Tasks

Pass a file path instead of a function to run a job in an isolated forked process, so heavy work never blocks your event loop:

cron.schedule('0 3 * * *', './tasks/backup.js');

Bundlers: background tasks fork a helper that node-cron resolves relative to its own files in node_modules. If you bundle your app (esbuild, webpack, Rollup, etc.), mark node-cron as external so it stays on disk (--external:node-cron, or externals: ['node-cron'] in webpack). Otherwise the fork fails with Cannot find module '.../daemon.js'. Inline function tasks are unaffected.

Runtime Control

Every task exposes a single consistent interface for control and inspection:

const task = cron.schedule('0 3 * * *', doWork, { name: 'nightly-backup', timezone: 'America/Sao_Paulo', }); task.stop(); // pause task.start(); // resume task.destroy(); // remove permanently task.getStatus(); // 'stopped' | 'idle' | 'running' | 'destroyed' task.getNextRun(); // next scheduled Date, or null task.lastRun(); // { date, result } or { date, error }, or null

Events

Tasks emit lifecycle events for observability:

task.on('execution:finished', (ctx) => console.log('result:', ctx.execution?.result)); task.on('execution:failed', (ctx) => console.error('failed:', ctx.execution?.error)); task.on('execution:overlap', () => console.warn('skipped: previous run still active')); task.on('execution:skipped', (ctx) => console.log('not elected:', ctx.reason)); task.on('task:failed', () => task.start()); // background task's daemon died unexpectedly (crash, OOM-kill); restart manually

All events: task:started, task:stopped, task:destroyed, task:failed, execution:started, execution:finished, execution:failed, execution:missed, execution:overlap, execution:maxReached, execution:skipped. See Events & Observability.

Cron Syntax

 # ┌────────────── second (optional)
 # │ ┌──────────── minute
 # │ │ ┌────────── hour
 # │ │ │ ┌──────── day of month
 # │ │ │ │ ┌────── month
 # │ │ │ │ │ ┌──── day of week
 # │ │ │ │ │ │
 # * * * * * *

| field | value | | ------------ | --------------------------------- | | second | 0-59 (optional) | | minute | 0-59 | | hour | 0-23 | | day of month | 1-31 (or L for the last day; L-3 offset from last; 15W, LW for nearest weekday) | | month | 1-12 (or names) | | day of week | 0-7 (or names, 0 or 7 are Sunday; 2#3, 5L) |

Supports ranges (1-5), steps (*/2), lists (1,15), named months/weekdays, L (last day of month), L-n (offset from the last day), # (nth weekday), <weekday>L (last weekday of month), W (nearest weekday), and ? (alias for * in the day fields, for Quartz-style expressions). See the Cron Syntax guide.

An inverted range wraps around the field instead of being rejected: 22-2 in the hour field means 22:00 through 02:59 (22,23,0,1,2), and sat-sun in the day-of-week field means saturday,sunday.

The W modifier in the day-of-month field fires on the nearest weekday (Monday-Friday) to a given day, without crossing the month boundary: 15W is the nearest weekday to the 15th, 1W the first weekday of the month, and LW the last weekday of the month. Only weekends are adjusted for; there is no holiday awareness.

The L-n form fires n days before the last day of the month (L-3 is the third-to-last day). In months where the offset reaches before the 1st (e.g. L-29 in February), it simply does not fire that month.

Note on Quartz: L, L-n, W, LW, #, <weekday>L and ? are borrowed from Quartz, but node-cron is not Quartz-compatible. Two differences matter:

  • Day-of-week numbering is standard cron, not Quartz: 0-7 with 0/7 = Sunday and 1 = Monday. In Quartz 1 = Sunday, so the same numeric weekday fires on a different day.
  • day-of-month and day-of-week are combined with AND (both must match), and may both be set; Quartz instead treats them as mutually exclusive and requires ? in one of them.

? is accepted purely as an alias for * in the day fields so Quartz-style expressions parse, not as a semantic compatibility guarantee.

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

When to Consider Something Else

  • Durable job queues with retries and priorities: use BullMQ, Agenda, or Sidequest
  • 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

Options

cron.schedule('0 3 * * *', task, { name: 'nightly-backup', timezone: 'America/Sao_Paulo', noOverlap: true, distributed: true, maxExecutions: 10, maxRandomDelay: 30000, });

See Scheduling Options for the full list.

Timezones and DST

Schedules match wall-clock time in the task's timezone. Across a daylight-saving fall-back the repeated hour runs once, so a sub-hourly schedule (for example */15) can pause for up to the length of the DST shift during that hour. If you need a fixed interval to keep firing uninterrupted across DST transitions, use a zone without DST, for example timezone: 'UTC'. See Timezones & DST for the full model.

Migrating from v3

v4 is a TypeScript rewrite with a smarter scheduler and a streamlined API. See the Migration Guide.

Sponsors

node-cron is zero-dependency infrastructure used in production by 220,000+ repositories. If it is part of your stack, sponsoring helps keep it tested, DST-correct, and maintained.

<!-- sponsors:begin --> <!-- auto-generated from sponsors.tpl.md by @goreleaser/sponsors, do not edit by hand --> <div align="center"> <p><strong>Silver sponsors</strong><br/> <a href="https://easysaas.at" target="_blank" rel="noopener sponsored"><img src="https://avatars.githubusercontent.com/u/24415042?s=64&v=4" alt="easySAAS" height="52"/></a> </p> </div> <!-- sponsors:end -->

Become a sponsor on GitHub Sponsors or Open Collective.

Issues

Feel free to submit issues and enhancement requests here.

Contributing

In general, we follow the "fork-and-pull" Git workflow.

  • Fork the repo on GitHub;
  • Commit changes to a branch in your fork;
  • Pull request "upstream" with your changes;

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

Please do not contribute code you did not write yourself, unless you are certain you have the legal ability to do so. Also ensure all contributed code can be distributed under the ISC License.

License

node-cron is under ISC License.

Dependencies Comparison

cron

Dependencies

luxon~3.7.0
@types/luxon~3.7.0

Dev Dependencies

jest30.2.0
husky9.1.7
sinon21.0.0
eslint8.57.1
prettier3.6.2
@swc/core1.15.3
@swc/jest0.2.39
cross-env7.0.3
@eslint/js9.39.1
typescript5.9.3
@types/jest30.0.0
@types/node22.19.1
lint-staged15.5.2
@types/sinon21.0.0
@commitlint/cli20.1.0
@fast-check/jest2.1.1
semantic-release25.0.2
typescript-eslint7.18.0
eslint-plugin-jest27.9.0
@semantic-release/git10.0.1
@semantic-release/npm13.1.2
eslint-config-prettier9.1.2
eslint-plugin-prettier5.5.4
@semantic-release/github12.0.2
@semantic-release/changelog6.0.3
@insurgent/commitlint-config20.0.0
@semantic-release/commit-analyzer13.0.1
@insurgent/conventional-changelog-preset10.0.0
@semantic-release/release-notes-generator14.1.0

Peer Dependencies

node-cron

Dependencies

Dev Dependencies

tslib^2.8.1
eslint^10.5.0
rollup^4.62.0
vitest^4.1.9
globals^16.1.0
@eslint/js^9.26.0
typescript^5.8.3
@types/node^22.15.3
@types/expect^1.20.4
rollup-plugin-dts^6.4.1
typescript-eslint^8.32.0
@vitest/coverage-v8^4.1.9
@rollup/plugin-replace^6.0.3
@rollup/plugin-commonjs^29.0.3
@rollup/plugin-typescript^12.3.0
@typescript-eslint/parser^8.32.0
@rollup/plugin-node-resolve^16.0.3
@typescript-eslint/eslint-plugin^8.32.0

Peer Dependencies

StarsIssuesVersionUpdatedⓘLast publish dateCreatedⓘPackage creation dateSizeⓘMinified + Gzipped size
C
cron
8,948374.4.0a month ago15 years agoinstall size 4.3 KB
N
node-cron
3,27874.6.02 months ago10 years agoinstall size 10.0 KB

Who's Using These Packages

cron

ng-zorro-antd
ng-zorro-antd

Angular UI Component Library based on Ant Design

aiva
aiva

AIVA (A.I. Virtual Assistant): General-purpose virtual assistant for developers.

openpaas-esn
openpaas-esn

Open PaaS Enterprise Social Network

bulk-mail-cli
bulk-mail-cli

Do quick, hassle-free email marketing with this small but very powerful tool! 🔥

earthcalc
earthcalc

This app calculates how much a distant object is obscured by the earth's curvature.

node-cron

vertex
vertex

适用于 PT 玩家的追剧刷流一体化综合管理工具

blog
blog

Next.js + Issues 博客解决方案 https://www.giscafer.com

bulk-mail-cli
bulk-mail-cli

Do quick, hassle-free email marketing with this small but very powerful tool! 🔥

webdog
webdog

AI native website change monitoring

Ruby-Hoshino-Bot
Ruby-Hoshino-Bot

💗 𝘽𝙄𝙀𝙉𝙑𝙀𝙉𝙄𝘿@ 𝘼𝙇 𝙍𝙀𝙋𝙊𝙎𝙄𝙏𝙊𝙍𝙄𝙊 𝙊𝙁𝙄𝘾𝙄𝘼𝙇 𝘿𝙀 𝙍𝙐𝘽𝙔 𝙃𝙊𝙎𝙃𝙄𝙉𝙊 𝘽𝙊𝙏, 𝙐𝙉 𝘽𝙊𝙏 𝘿𝙀 𝙀𝙉𝙏𝙍𝙀𝙏𝙀𝙉𝙄𝘿𝙄𝙈𝙄𝙀𝙉𝙏𝙊, 𝙅𝙐𝙀𝙂𝙊𝙎 𝙍𝙋𝙂, 𝙂𝙀𝙎𝙏𝙄𝙊́𝙉 𝘿𝙀 𝙂𝙍𝙐𝙋𝙊𝙎 𝙔 𝙈𝙐𝘾𝙃𝙊 𝙈𝘼𝙎. 𝙎𝙄 𝙏𝙀 𝙂𝙐𝙎𝙏𝘼 𝙀𝙎𝙏𝙀 𝙋𝙍𝙊𝙔𝙀𝘾𝙏𝙊, 𝘼𝙋𝙊𝙔𝘼𝙉𝙊𝙎 𝘾𝙊𝙉 𝙐𝙉𝘼 𝙀𝙎𝙏𝙍𝙀𝙇𝙇𝘼 🌟