node-schedule vs croner vs node-cron vs bull vs agenda vs bree
Node.js Job Scheduling Libraries Comparison
1 Year
node-schedulecronernode-cronbullagendabreeSimilar Packages:
What's Node.js Job Scheduling Libraries?

Job scheduling libraries in Node.js are used to manage and execute scheduled tasks, such as recurring jobs or one-off tasks at specific times. These libraries provide developers with tools to create, manage, and execute jobs efficiently, ensuring that tasks are performed at the right time without manual intervention. They are essential for applications that require background processing, delayed execution, or periodic tasks, enhancing the overall functionality and automation of Node.js applications.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
node-schedule2,106,6879,16435 kB1662 years agoMIT
croner1,916,9392,157104 kB15 months agoMIT
node-cron945,0663,01768.4 kB170a year agoISC
bull906,75815,809309 kB1503 months agoMIT
agenda122,5369,481353 kB350-MIT
bree21,5433,11690.5 kB307 months agoMIT
Feature Comparison: node-schedule vs croner vs node-cron vs bull vs agenda vs bree

Job Persistence

  • node-schedule:

    Node-Schedule does not provide job persistence, focusing instead on scheduling jobs in memory. It is ideal for applications that can handle job loss on restart.

  • croner:

    Croner does not support job persistence, as it is designed for simple scheduling without the need for storing job states. It is best suited for short-lived tasks that do not require tracking.

  • node-cron:

    Node-Cron does not have built-in job persistence; it is a lightweight solution for scheduling tasks that run in memory. This makes it suitable for applications where job tracking is not critical.

  • bull:

    Bull uses Redis for job persistence, ensuring that jobs are stored reliably and can be processed even after application crashes or restarts. This makes Bull a great choice for applications that require high reliability and durability in job processing.

  • agenda:

    Agenda provides built-in support for job persistence using MongoDB, allowing jobs to be stored and retrieved even after application restarts. This is crucial for long-running applications where job state needs to be maintained across sessions.

  • bree:

    Bree does not provide job persistence out of the box, as it focuses on in-memory job scheduling and execution using worker threads. If persistence is needed, developers must implement their own storage mechanism.

Concurrency Support

  • node-schedule:

    Node-Schedule does not support concurrency; it schedules jobs to run sequentially in the same event loop. It is suitable for applications where job execution order is important.

  • croner:

    Croner does not support concurrency, as it is designed for simple scheduling of jobs that run sequentially. It is best for applications where tasks do not need to run in parallel.

  • node-cron:

    Node-Cron does not support concurrency natively, as it runs jobs in the same event loop. For concurrent execution, developers need to implement their own solution.

  • bull:

    Bull supports concurrency through its worker model, allowing multiple workers to process jobs from the queue simultaneously. This is essential for applications that need to scale job processing effectively.

  • agenda:

    Agenda supports concurrent job execution by allowing multiple instances of the application to process jobs simultaneously. This is beneficial for scaling applications that need to handle a high volume of jobs.

  • bree:

    Bree excels in concurrency, leveraging worker threads to run multiple jobs in parallel without blocking the main event loop. This makes it highly efficient for CPU-intensive tasks.

Ease of Use

  • node-schedule:

    Node-Schedule provides a flexible API for scheduling jobs using both cron syntax and date objects, making it easy to use for various scheduling needs.

  • croner:

    Croner is very easy to use, allowing developers to schedule jobs with simple cron syntax. Its lightweight nature makes it a quick solution for basic scheduling needs.

  • node-cron:

    Node-Cron is straightforward and easy to implement, making it a popular choice for developers who need to schedule tasks quickly without additional complexity.

  • bull:

    Bull has a slightly steeper learning curve due to its advanced features, but it provides comprehensive documentation to help developers get started with job queues and processing.

  • agenda:

    Agenda offers a user-friendly API that simplifies job scheduling and management. Its integration with MongoDB makes it easy to manage jobs without complex configurations.

  • bree:

    Bree is designed with simplicity in mind, providing a clean API for scheduling jobs using worker threads. Its modern approach makes it easy to implement and use.

Advanced Features

  • node-schedule:

    Node-Schedule allows for both cron-like scheduling and scheduling based on JavaScript Date objects, providing flexibility for various scheduling needs.

  • croner:

    Croner is focused on simplicity and does not offer advanced features, making it suitable for basic scheduling without the need for complex configurations.

  • node-cron:

    Node-Cron is a basic scheduler and does not provide advanced features like retries or job management, focusing solely on executing scheduled tasks.

  • bull:

    Bull provides extensive features like delayed jobs, job retries, rate limiting, and job events, making it a powerful choice for applications that require robust job processing capabilities.

  • agenda:

    Agenda supports advanced features like job prioritization, job cancellation, and job scheduling based on specific dates or intervals, making it suitable for complex scheduling scenarios.

  • bree:

    Bree includes advanced features such as job retries, job timeouts, and the ability to run jobs at specific intervals or cron schedules, offering flexibility for various use cases.

Community and Support

  • node-schedule:

    Node-Schedule has a decent community and documentation, offering enough resources for developers to implement scheduling effectively.

  • croner:

    Croner is lightweight and has a smaller community, but its simplicity makes it easy to use without extensive support requirements.

  • node-cron:

    Node-Cron is widely used and has a strong community, providing ample resources and documentation for developers.

  • bull:

    Bull has a large user base and extensive documentation, making it easy to find solutions and community support for job processing challenges.

  • agenda:

    Agenda has a strong community and is well-documented, providing resources and support for developers looking to implement job scheduling in their applications.

  • bree:

    Bree is relatively new but has gained popularity quickly, with a growing community and active maintenance, ensuring developers can find support and resources easily.

How to Choose: node-schedule vs croner vs node-cron vs bull vs agenda vs bree
  • node-schedule:

    Select Node-Schedule if you need a flexible job scheduler that allows you to schedule jobs using both cron syntax and date objects. It is suitable for applications that require a combination of one-off and recurring jobs.

  • croner:

    Use Croner if you prefer a lightweight and simple cron-like scheduling library that allows you to schedule jobs using cron syntax. It is suitable for applications that need straightforward scheduling without the overhead of a more complex job management system.

  • node-cron:

    Choose Node-Cron if you want a simple and easy-to-use cron job scheduler for Node.js that allows you to schedule tasks using cron syntax. It is ideal for applications that require periodic execution of tasks without the need for persistent job storage.

  • bull:

    Select Bull if you need a robust queue system with advanced features like job retries, rate limiting, and delayed jobs. Bull is perfect for applications that require reliable job processing and can benefit from Redis for job storage and management.

  • agenda:

    Choose Agenda if you need a simple yet powerful job scheduling solution that integrates seamlessly with MongoDB. It is ideal for applications that require persistent job storage and supports complex job scheduling with a straightforward API.

  • bree:

    Opt for Bree if you require a modern job scheduler that supports worker threads and is designed for high-performance applications. Bree is particularly useful for applications that need to run jobs concurrently and efficiently without blocking the event loop.

README for node-schedule

Node Schedule

NPM version Downloads Build Status Coverage Status Join the chat at https://gitter.im/node-schedule/node-schedule

NPM

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).

Node 6+ is supported.

Overview

Node Schedule is for time-based scheduling, not interval-based scheduling.

While you can easily bend it to your will, if you only want to do something like "run this function every 5 minutes", toad-scheduler would be a better choice. But if you want to, say, "run this function at the :20 and :50 of every hour on the third Tuesday of every month," you'll find that Node Schedule suits your needs better. Additionally, Node Schedule has Windows support, unlike true cron, since the node runtime is now fully supported.

Note that Node Schedule is designed for in-process scheduling, i.e. scheduled jobs will only fire as long as your script is running, and the schedule will disappear when execution completes. If you need to schedule jobs that will persist even when your script isn't running, consider using actual cron.

In case you need durable jobs that persist across restarts and lock system compatible with multi-node deployments, try agenda or bree.

Usage

Installation

You can install using npm.

npm install node-schedule

Jobs and Scheduling

Every scheduled job in Node Schedule is represented by a Job object. You can create jobs manually, then execute the schedule() method to apply a schedule, or use the convenience function scheduleJob() as demonstrated below.

Job objects are EventEmitters, and emit the following events:

  • A run event after each execution.
  • A scheduled event each time they're scheduled to run.
  • A canceled event when an invocation is canceled before it's executed.
    Note that canceled is the single-L American spelling.
  • An error event when a job invocation triggered by a schedule throws or returns a rejected Promise.
  • A success event when a job invocation triggered by a schedule returns successfully or returns a resolved Promise. In any case, the success event receives the value returned by the callback or in case of a promise, the resolved value.

(Both the scheduled and canceled events receive a JavaScript date object as a parameter).
Note that jobs are scheduled the first time immediately, so if you create a job using the scheduleJob() convenience method, you'll miss the first scheduled event, but you can query the invocation manually (see below).

Cron-style Scheduling

The cron format consists of:

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    │
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)

Examples with the cron format:

const schedule = require('node-schedule');

const job = schedule.scheduleJob('42 * * * *', function(){
  console.log('The answer to life, the universe, and everything!');
});

Execute a cron job when the minute is 42 (e.g. 19:42, 20:42, etc.).

And:

const job = schedule.scheduleJob('0 17 ? * 0,4-6', function(){
  console.log('Today is recognized by Rebecca Black!');
});

Execute a cron job every 5 Minutes = */5 * * * *

You can also get when it is scheduled to run for every invocation of the job:

const job = schedule.scheduleJob('0 1 * * *', function(fireDate){
  console.log('This job was supposed to run at ' + fireDate + ', but actually ran at ' + new Date());
});

This is useful when you need to check if there is a delay of the job invocation when the system is busy, or save a record of all invocations of a job for audit purpose.

Unsupported Cron Features

Currently, W (nearest weekday) and L (last day of month/week) are not supported. Most other features supported by popular cron implementations should work just fine, including # (nth weekday of the month).

cron-parser is used to parse crontab instructions.

Date-based Scheduling

Say you very specifically want a function to execute at 5:30am on December 21, 2012. Remember - in JavaScript - 0 - January, 11 - December.

const schedule = require('node-schedule');
const date = new Date(2012, 11, 21, 5, 30, 0);

const job = schedule.scheduleJob(date, function(){
  console.log('The world is going to end today.');
});

To use current data in the future you can use binding:

const schedule = require('node-schedule');
const date = new Date(2012, 11, 21, 5, 30, 0);
const x = 'Tada!';
const job = schedule.scheduleJob(date, function(y){
  console.log(y);
}.bind(null,x));
x = 'Changing Data';

This will log 'Tada!' when the scheduled Job runs, rather than 'Changing Data', which x changes to immediately after scheduling.

Recurrence Rule Scheduling

You can build recurrence rules to specify when a job should recur. For instance, consider this rule, which executes the function every hour at 42 minutes after the hour:

const schedule = require('node-schedule');

const rule = new schedule.RecurrenceRule();
rule.minute = 42;

const job = schedule.scheduleJob(rule, function(){
  console.log('The answer to life, the universe, and everything!');
});

You can also use arrays to specify a list of acceptable values, and the Range object to specify a range of start and end values, with an optional step parameter. For instance, this will print a message on Thursday, Friday, Saturday, and Sunday at 5pm:

const rule = new schedule.RecurrenceRule();
rule.dayOfWeek = [0, new schedule.Range(4, 6)];
rule.hour = 17;
rule.minute = 0;

const job = schedule.scheduleJob(rule, function(){
  console.log('Today is recognized by Rebecca Black!');
});

Timezones are also supported. Here is an example of executing at the start of every day in the UTC timezone.

const rule = new schedule.RecurrenceRule();
rule.hour = 0;
rule.minute = 0;
rule.tz = 'Etc/UTC';

const job = schedule.scheduleJob(rule, function(){
  console.log('A new day has begun in the UTC timezone!');
});

A list of acceptable tz (timezone) values can be found at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

RecurrenceRule properties

  • second (0-59)
  • minute (0-59)
  • hour (0-23)
  • date (1-31)
  • month (0-11)
  • year
  • dayOfWeek (0-6) Starting with Sunday
  • tz

Note: It's worth noting that the default value of a component of a recurrence rule is null (except for second, which is 0 for familiarity with cron). If we did not explicitly set minute to 0 above, the message would have instead been logged at 5:00pm, 5:01pm, 5:02pm, ..., 5:59pm. Probably not what you want.

Object Literal Syntax

To make things a little easier, an object literal syntax is also supported, like in this example which will log a message every Sunday at 2:30pm:

const job = schedule.scheduleJob({hour: 14, minute: 30, dayOfWeek: 0}, function(){
  console.log('Time for tea!');
});

Set StartTime and EndTime

It will run after 5 seconds and stop after 10 seconds in this example. The ruledat supports the above.

const startTime = new Date(Date.now() + 5000);
const endTime = new Date(startTime.getTime() + 5000);
const job = schedule.scheduleJob({ start: startTime, end: endTime, rule: '*/1 * * * * *' }, function(){
  console.log('Time for tea!');
});

Graceful Shutdown.

You can shutdown jobs gracefully.
gracefulShutdown() will cancel all jobs and return Promise.
It will wait until all jobs are terminated.

schedule.gracefulShutdown();

You can also gracefully shutdown jobs when a system interrupt occurs.

process.on('SIGINT', function () { 
  schedule.gracefulShutdown()
  .then(() => process.exit(0))
}

Handle Jobs and Job Invocations

There are some function to get information for a Job and to handle the Job and Invocations.

job.cancel(reschedule)

You can invalidate any job with the cancel() method:

j.cancel();

All planned invocations will be canceled. When you set the parameter reschedule to true then the Job is newly scheduled afterwards.

job.cancelNext(reschedule)

This method invalidates the next planned invocation or the job. When you set the parameter reschedule to true then the Job is newly scheduled afterwards.

job.reschedule(spec)

This method cancels all pending invocation and registers the Job completely new again using the given specification. Return true/false on success/failure.

job.nextInvocation()

This method returns a Date object for the planned next Invocation for this Job. If no invocation is planned the method returns null.

Contributing

This module was originally developed by Matt Patenaude who eventually passed over maintainer's mantle over to Tejas Manohar.

Currently it is being maintained by Igor Savin and our amazing community.

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 guide!

Copyright and license

Copyright 2015 Matt Patenaude.

Licensed under the MIT License.