kelektiv /node-cron

Cron for NodeJS.

★ 8,954⑂ 651👁 99⑃ 474● 611▤ 55
TypeScriptMITCreated 2010-06-23
Download: v4.4.0v4.4.0 ↓4.4.02025-12-09
+0
Daily
8,954
stars
651
forks
99
watchers
474
prs
611
issues
55
releases

README

cron is a robust tool for running jobs (functions or commands) on schedules defined using the cron syntax.
  
  Perfect for tasks like data backups, notifications, and many more!


 Cron for Node.js










 🌟 Features

- execute a function whenever your scheduled job triggers
- execute a job external to the javascript process (like a system command) using child_process
- use a Date or Luxon DateTime object instead of cron syntax as the trigger for your callback
- use an additional slot for seconds (leaving it off will default to 0 and match the Unix behavior)

 🚀 Installation

bash
npm install cron


 Table of Contents

1. Features
2. Installation
3. Migrating
4. Basic Usage
5. Cron Patterns
   - Cron Syntax Overview
   - Supported Ranges
6. API
   - Standalone Functions
   - CronJob Class
   - CronTime Class
7. Gotchas
8. Community
   - Join the Community
9. Contributing
   - General Contribution
   - Submitting Bugs/Issues
10. Acknowledgements
11. License

 ⬆ Migrating

v4 dropped Node v16 and renamed the job.running property:


  Migrating from v3 to v4

 Dropped Node version

Node v16 is no longer supported. Upgrade your Node installation to Node v18 or above

 Property renamed and now read-only

You can no longer set the running property (now isActive). It is read-only. To start or stop a cron job, use job.start() and job.stop().



v3 introduced TypeScript and tighter Unix cron pattern alignment:


  Migrating from v2 to v3

 Month & day-of-week indexing changes

- Month Indexing: Changed from 0-11 to 1-12. So you need to increment all numeric months by 1.

- Day-of-Week Indexing: Support added for 7 as Sunday.

 Adjustments in CronJob

- The constructor no longer accepts an object as its first and only params. Use CronJob.from(argsObject) instead.
- Callbacks are now called in the order they were registered.
- nextDates(count?: number) now always returns an array (empty if no argument is provided). Use nextDate() instead for a single date.

 Removed methods

- removed job() method in favor of new CronJob(...args) / CronJob.from(argsObject)

- removed time() method in favor of new CronTime()



 🛠 Basic Usage

javascript
import { CronJob } from 'cron';

const job = new CronJob(
	'     ', // cronTime
	function () {
		console.log('You will see this message every second');
	}, // onTick
	null, // onComplete
	true, // start
	'America/Los_Angeles' // timeZone
);
// job.start() is optional here because of the fourth parameter set to true.


javascript
// equivalent job using the "from" static method, providing parameters as an object
const job = CronJob.from({
	cronTime: '     ',
	onTick: function () {
		console.log('You will see this message every second');
	},
	start: true,
	timeZone: 'America/Los_Angeles'
});


 Note: In the first example above, the fourth parameter to CronJob() starts the job automatically. If not provided or set to falsy, you must explicitly start the job using job.start().

For more advanced examples, check the examples 

Top issues

Discussions

Latest release

v4.4.0 v4.4.0 2025-12-09
4.4.0 (2025-12-09)

 ✨ Features

 update node versions to include 24 and 25 (1031) (b228e7c), closes 1000

 ♻️ Chores

 deps: lock file maintenance (570f9bc)
 deps: lock file maintenance (1026) (ac05b84)

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON