NPM Cron Jobs Packages
NPM offers several cron job packages for Node.js applications. Each has different features, from simple cron expressions to distributed job queues.
How to Set Up Cron Jobs in NPM/Node.js
1
node-cron (Most Popular)
Simple and lightweight cron scheduler
Code
npm install node-cron
const cron = require('node-cron');
cron.schedule('*/5 * * * *', () => {
console.log('Running every 5 minutes');
});2
cron (Feature-rich)
More features including timezone support
Code
npm install cron
const { CronJob } = require('cron');
const job = new CronJob(
'*/5 * * * *',
function() {
console.log('Running every 5 minutes');
},
null,
true,
'America/New_York'
);3
Agenda (MongoDB-backed)
Persistent job scheduling with MongoDB
Code
npm install agenda
const Agenda = require('agenda');
const agenda = new Agenda({ db: { address: mongoConnectionString } });
agenda.define('send email', async job => {
await sendEmail(job.attrs.data.to);
});
await agenda.every('5 minutes', 'send email', { to: 'user@example.com' });
await agenda.start();NPM/Node.js Cron Limitations vs CronUptime
NPM/Node.js Limitations
- •All require a running Node.js process
- •Jobs lost on restart (except Agenda)
- •No built-in monitoring dashboard
- •Agenda requires MongoDB infrastructure
- •Scaling requires additional setup
CronUptime Advantages
- ✓No Node.js process required
- ✓No NPM packages to manage
- ✓Works with any HTTP endpoint
- ✓Built-in monitoring and alerts
- ✓Free tier available
Why Use CronUptime Instead?
While NPM/Node.js cron jobs work for basic use cases, managing infrastructure for scheduled tasks adds complexity. CronUptime offers a simpler, serverless alternative.
No Infrastructure
We handle execution. No servers to maintain.
Reliable Timing
Built on Cloudflare for 99.9%+ uptime.
Any Endpoint
Works with any HTTP endpoint on any platform.
Frequently Asked Questions
node-cron is the most popular for simple scheduling. cron offers timezone support. Agenda is best for persistent jobs with MongoDB. Choose based on your needs.
node-cron is simpler and lighter. The 'cron' package offers more features like timezone support, onComplete callbacks, and better TypeScript support.
Use Agenda with MongoDB, or Bull/BullMQ with Redis for persistent job storage. Alternatively, use an external service like CronUptime that doesn't depend on your app's uptime.
Quick Reference
Cron Expression:
*/5 * * * *Human Readable:
every 5 minutes
Cron Jobs on Other Platforms
Try CronUptime Free
Schedule HTTP requests without managing NPM/Node.js infrastructure.
Try it now - Free
Create a cron job running every 5 minutes. No sign-up required.