What is node-schedule?
The node-schedule npm package is a flexible cron-like and not-cron-like job scheduler for Node.js. It allows you to schedule jobs (arbitrary functions) for execution at specific dates, with optional recurrence rules. It is suitable for building job schedulers, task reminders, or any other automation based on time events.
What are node-schedule's main functionalities?
One-time jobs
Schedule a job to be executed once at a specific date and time.
const schedule = require('node-schedule');
const date = new Date(2023, 3, 21, 5, 30, 0);
const job = schedule.scheduleJob(date, function() {
console.log('This job is run once at the specified date.');
});
Recurring jobs using cron-style scheduling
Schedule a job to be executed on a recurring basis using a cron string to specify the frequency.
const schedule = require('node-schedule');
const job = schedule.scheduleJob('*/5 * * * *', function() {
console.log('This job runs every 5 minutes.');
});
Recurring jobs using object literal syntax
Schedule a job using a more human-readable object literal syntax for setting the schedule.
const schedule = require('node-schedule');
const job = schedule.scheduleJob({hour: 14, minute: 30, dayOfWeek: 1}, function() {
console.log('This job runs at 2:30pm every Monday.');
});
Canceling jobs
Cancel a scheduled job before it is executed.
const schedule = require('node-schedule');
const job = schedule.scheduleJob('*/5 * * * *', function() {
console.log('This job will be canceled.');
});
job.cancel();
Other packages similar to node-schedule
cron
The 'cron' package is similar to node-schedule and is used for scheduling jobs to run at specific times or intervals. It uses the Unix cron string format to define schedules and is widely used for its simplicity and familiarity to those with Unix/Linux experience.
agenda
Agenda is a more feature-rich job scheduling library for Node.js. It supports persistence with MongoDB, which allows scheduled jobs to be stored and run across server restarts. It also offers more control over job queuing and locking, making it suitable for more complex scheduling needs.
bull
Bull is a Redis-based queue system for Node.js. It is often used for job scheduling as well as for processing distributed jobs in the background. It offers advanced features like repeatable jobs, rate limiting, and job prioritization, making it a good choice for high-performance job processing.
bree
Bree is a job scheduler for Node.js that supports cron, dates, ms (milliseconds), later, and human-friendly strings for job scheduling. It uses workers for parallel job processing and includes support for job timeouts and graceful cancellation. It's a modern alternative with a focus on reliability and concurrency.
node-schedule
Announcement: Node Schedule is looking for add additional collaborators with commit access. If you are actively involved in open source, ping Tejas Manohar (via email, Twitter, etc.) to express interest. Those who already contribute to the project are preferred.
node-schedule is a flexible cron-like and not-cron-like job scheduler for Node.js. It allows you to schedule jobs (arbitrary functions) for execution at specific dates, with optional recurrence rules. It only uses a single timer at any given time (rather than reevaluating upcoming jobs every second/minute).
Read more about the module's core functions on the About page of the wiki.
Usage
Check out our wonderful wiki for usage instructions.
Contributing
This module was originally developed by Matt Patenaude, and is now maintained by Tejas Manohar and other wonderful contributors.
We'd love to get your contributions. Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit.
Before jumping in, check out our Contributing page on the wiki!
Copyright and license
Copyright 2015 Matt Patenaude.
Licensed under the [MIT License] license.