Cron Job in Node.js

Node.js provides several libraries for scheduling cron jobs, with node-cron being the most popular. However, running cron jobs in your Node.js application requires keeping the process alive 24/7.

How to Set Up Cron Jobs in Node.js

1

Install node-cron

Add the node-cron package to your project

Code
npm install node-cron
2

Create a scheduled task

Use cron expressions to schedule your tasks

Code
const cron = require('node-cron');

// Run every 5 minutes
cron.schedule('*/5 * * * *', () => {
  console.log('Running task every 5 minutes');
  // Your task logic here
});
3

Keep the process running

Your Node.js process must stay alive for cron to work

Code
// Use PM2 or similar for production
// pm2 start app.js --name "cron-service"

Node.js Cron Limitations vs CronUptime

Node.js Limitations

  • Requires a constantly running Node.js process
  • Server costs for 24/7 uptime
  • Single point of failure if the process crashes
  • No built-in monitoring or alerting
  • Timezone handling can be tricky

CronUptime Advantages

  • No server required - we handle execution
  • Built-in monitoring and failure alerts
  • Runs on Cloudflare's global edge network
  • Free tier available for small workloads
  • Simple HTTP-based - works with any endpoint

Why Use CronUptime Instead?

While 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 a popular Node.js package that allows you to schedule tasks using cron expressions. It's lightweight and easy to use, but requires your Node.js process to be running continuously.
Use node-cron with the expression '*/5 * * * *'. Install with 'npm install node-cron', then use cron.schedule('*/5 * * * *', () => { /* your code */ }).
node-cron uses traditional cron expressions while node-schedule offers more flexible scheduling options including date-based scheduling. node-cron is lighter and more commonly used for standard cron patterns.

Quick Reference

Cron Expression:

*/5 * * * *

Human Readable:

every 5 minutes

Cron Jobs on Other Platforms

Try CronUptime Free

Schedule HTTP requests without managing Node.js infrastructure.

Try it now - Free

Create a cron job running every 5 minutes. No sign-up required.

The URL that will be called. You can also paste a curl command here.

Runs for 7 daysSign in for permanent