This comparison evaluates seven prominent Node.js packages for handling time-based tasks: agenda, bree, bull, cron, later, node-cron, and node-schedule. These tools fall into two distinct architectural categories: in-process schedulers that run jobs within the current Node.js event loop (ideal for simple cron jobs or single-server setups) and persistent queue systems that rely on external databases like MongoDB or Redis to manage job state, retries, and distribution across multiple workers. Understanding the trade-offs between ease of setup, reliability during crashes, and scalability is critical for choosing the right tool for your backend infrastructure.
When building backend services in Node.js, handling delayed tasks, recurring jobs, and background processing is a common requirement. The ecosystem offers several solutions, ranging from simple in-process timers to robust, distributed queue systems. The choice between packages like agenda, bree, bull, cron, later, node-cron, and node-schedule fundamentally depends on whether you need persistence and distribution or just simple scheduling.
Let's break down these tools by their architectural patterns, execution models, and real-world usage.
The most critical decision is whether your jobs need to survive a server crash or run across multiple servers.
agenda and bull store job definitions and states in an external database. This ensures that if your server crashes, pending jobs are not lost and can be picked up by another worker.
agenda uses MongoDB to store jobs. It acts as both the scheduler and the processor.
// agenda: Define and schedule a job
const agenda = new Agenda({ db: { address: 'mongodb://localhost/agenda' } });
agenda.define('send email', async (job) => {
await sendEmail(job.attrs.data.to);
});
await agenda.start();
await agenda.every('10 minutes', 'send email', { to: 'user@example.com' });
bull uses Redis to manage highly performant queues. It separates the concept of producing jobs (adding to the queue) and consuming them (workers processing them).
// bull: Create a queue and add a job
const Queue = require('bull');
const emailQueue = new Queue('email tasks', 'redis://127.0.0.1:6379');
emailQueue.add({ to: 'user@example.com' }, { attempts: 3, backoff: 5000 });
// Worker process
emailQueue.process(async (job) => {
await sendEmail(job.data.to);
});
node-cron, node-schedule, bree, and cron run entirely within the Node.js process memory. If the process dies, scheduled jobs are lost unless you have external logic to re-queue them.
node-cron is a lightweight implementation of standard cron syntax.
// node-cron: Simple cron job
const cron = require('node-cron');
cron.schedule('*/10 * * * *', () => {
console.log('Running every 10 minutes');
});
node-schedule offers more flexibility than standard cron, allowing you to schedule jobs for specific dates or using rule-based logic.
// node-schedule: Schedule for a specific date or rule
const schedule = require('node-schedule');
// Run at 4:30 AM every day
const job = schedule.scheduleJob('4 30 * * *', () => {
console.log('Good morning!');
});
// Or run at a specific Date object
const futureDate = new Date(Date.now() + 60000);
schedule.scheduleJob(futureDate, () => {
console.log('Ran after 1 minute');
});
bree takes a different approach by managing jobs as separate files that run in worker threads or child processes, preventing long-running tasks from blocking the main event loop.
// bree: Configure and start
const Bree = require('bree');
const bree = new Bree({
root: './jobs', // Directory containing job files
jobs: [
{ name: 'clean-up', interval: 'every 5 minutes' },
{ name: 'report', cron: '0 0 * * *' }
]
});
bree.start();
How you define "when" a job runs varies significantly between these libraries.
cron and node-cron strictly adhere to standard Unix cron syntax (minute, hour, day, month, weekday). This is familiar to DevOps engineers but can be limiting for complex intervals like "every 90 minutes."
// cron / node-cron: Standard syntax only
// This works: Every hour
job.schedule('0 * * * *');
// This is hard: Every 90 minutes requires complex cron math
job.schedule('0 */90 * * *'); // Incorrect logic for 90 mins across hours
node-schedule supports cron syntax but also allows for RecurrenceRule objects and natural language-like intervals, making it easier to express non-standard timings.
// node-schedule: Flexible rules
const rule = new schedule.RecurrenceRule();
rule.minute = 0;
rule.hour = 2;
rule.dayOfWeek = 1; // Mondays
schedule.scheduleJob(rule, () => {
console.log('Every Monday at 2 AM');
});
agenda uses human-readable strings powered by the human-interval and cron-parser libraries, offering the most readable syntax for business logic.
// agenda: Human readable
await agenda.every('5 minutes', 'calculate stats');
await agenda.schedule('in 2 hours', 'send reminder', { userId: 123 });
await agenda.schedule('tomorrow at noon', 'daily report');
bree supports both cron syntax and human-readable intervals (via human-interval), combining flexibility with its worker-thread architecture.
// bree: Mixed syntax support
jobs: [
{ name: 'task1', interval: 'every 5 minutes' },
{ name: 'task2', cron: '0 12 * * *' }
]
later was famous for its extremely flexible scheduling logic, allowing complex combinations of time constraints. However, due to its deprecated status, it should not be used in new projects.
// later: (Deprecated) Complex scheduling example
// DO NOT USE IN NEW PROJECTS
const schedule = later.schedule(later.parse.cron('*/5 * * * *'));
When running jobs in production, you must handle failures, concurrency, and server restarts.
bull and agenda excel here. Since job state is in Redis or MongoDB, if a worker crashes while processing a job, the system detects the timeout and can re-queue the job automatically.
// bull: Automatic retry on failure
queue.add({ data }, {
attempts: 3,
backoff: {
type: 'exponential',
delay: 1000
}
});
In contrast, node-cron and node-schedule have no built-in recovery. If the server restarts, you must rely on the code re-executing the schedule definition on startup. They also lack built-in mechanisms to detect if a job is stuck.
A common pitfall in Node.js is running heavy CPU tasks in the main event loop, which blocks incoming requests.
bree solves this by design. Each job runs in a separate worker thread or child process. This isolates crashes and prevents CPU-heavy tasks from freezing your API.
// bree: Job runs in isolated worker (jobs/clean-up.js)
module.exports = async () => {
// Heavy CPU usage here won't block the main scheduler
performHeavyCalculation();
};
bull also encourages running workers in separate processes or even on different servers, naturally isolating the load.
agenda, node-cron, and node-schedule run jobs in the main thread by default. You must manually spawn child processes or worker threads if your jobs are CPU-intensive.
// node-schedule: Manual worker spawning required for heavy tasks
schedule.scheduleJob('*/5 * * * *', () => {
const worker = new Worker('./heavy-task.js');
worker.on('message', (result) => console.log(result));
});
laterIt is crucial to note that later is no longer actively maintained. The repository has seen minimal activity in recent years, and it does not align well with modern Node.js practices. Using it introduces security risks and potential compatibility issues with newer Node versions. For any logic requiring complex scheduling, node-schedule or agenda are the recommended modern alternatives.
| Feature | agenda | bull | bree | node-cron | node-schedule | cron | later |
|---|---|---|---|---|---|---|---|
| Storage | MongoDB | Redis | Memory / Files | Memory | Memory | Memory | Memory |
| Persistence | ✅ Yes | ✅ Yes | ❌ No | ❌ No | ❌ No | ❌ No | ❌ No |
| Distributed | ✅ Yes | ✅ Yes | ❌ No | ❌ No | ❌ No | ❌ No | ❌ No |
| Isolation | Main Thread | External Worker | Worker Thread | Main Thread | Main Thread | Main Thread | Main Thread |
| Syntax | Human/Cron | Cron/Config | Human/Cron | Cron | Cron/Rules | Cron | Complex |
| Status | Active | Active | Active | Active | Active | Active | ⚠️ Deprecated |
Your choice should depend on the criticality of the jobs and your infrastructure:
bull if you have Redis, or agenda if you prefer MongoDB. These provide the necessary safety nets for retries, persistence, and distributed processing.bree. Its worker-thread architecture is uniquely suited for preventing event-loop blocking without the complexity of setting up a full queue system.node-cron for standard needs or node-schedule if you need more flexible timing rules. They are lightweight and easy to implement for non-critical tasks like cache warming or log rotation.later. Its lack of maintenance makes it a liability compared to the robust alternatives available today.Choose node-cron if you need a straightforward, zero-dependency implementation of cron syntax for in-process scheduling. It is perfect for simple tasks like cleaning up logs or sending daily emails on a single server instance. Do not use it if you need job persistence, distributed execution, or protection against server crashes, as jobs are lost when the process dies.
Choose cron (often installed as cron or node-cron depending on context, but here referring to the specific implementation) if you need a pure JavaScript cron parser with no external dependencies for simple, in-process scheduling. It is suitable for lightweight tasks on a single server where job persistence across restarts is not required. Note that this package is often confused with node-cron; ensure you select the one with active maintenance for your specific syntax needs.
Choose node-schedule if you need flexible scheduling beyond standard cron syntax, such as firing jobs based on specific dates, times, or natural language rules (e.g., 'every 2 hours'). It is an in-process scheduler ideal for applications that require complex timing logic without the overhead of external databases. Like other in-process tools, it does not support distributed job locking or persistence across restarts.
Choose bull if you require a high-performance, distributed job queue with advanced features like priority queues, rate limiting, and automatic retries backed by Redis. It is the industry standard for heavy-duty background processing where reliability and scalability are paramount. Avoid it if you cannot introduce Redis as a dependency or if your use case is limited to simple, single-server cron jobs.
Choose agenda if you need a robust, database-backed job queue with human-readable scheduling syntax and are already using MongoDB. It excels in scenarios requiring job persistence, retries, and locking mechanisms to prevent duplicate execution across multiple server instances. However, avoid it if you cannot tolerate the overhead of database connections for every job check or if your project does not already depend on MongoDB.
Avoid using later for new projects as it is largely deprecated and unmaintained. While it historically offered powerful human-readable scheduling logic, its lack of updates poses security and compatibility risks. Modern alternatives like node-schedule or bree provide similar or superior functionality with active support and better integration with current Node.js versions.
Choose bree if you prefer a modern, lightweight scheduler that runs jobs in separate worker threads or processes to prevent blocking the main event loop. It is ideal for CPU-intensive tasks or when you want strict isolation between jobs without the complexity of setting up Redis or MongoDB. It supports cron syntax and simple intervals but lacks the advanced distributed queue features of bull or agenda.
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.
npm install node-cron
import cron from 'node-cron';
cron.schedule('* * * * *', () => {
console.log('running a task every minute');
});
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 });
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,
});
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, orexternals: ['node-cron']in webpack). Otherwise the fork fails withCannot find module '.../daemon.js'. Inline function tasks are unaffected.
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
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.
# ┌────────────── 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>Land?are borrowed from Quartz, but node-cron is not Quartz-compatible. Two differences matter:
- Day-of-week numbering is standard cron, not Quartz:
0-7with0/7= Sunday and1= Monday. In Quartz1= 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.
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.
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.
v4 is a TypeScript rewrite with a smarter scheduler and a streamlined API. See the Migration Guide.
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.
Become a sponsor on GitHub Sponsors or Open Collective.
Feel free to submit issues and enhancement requests here.
In general, we follow the "fork-and-pull" Git workflow.
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.
node-cron is under ISC License.