Using Scheduling with NodeJS

A brief introduction to use cron scheduling in node

node-cron is a possible solution for scheduling in NodeJS. It’s very simple to use.

First, run the following command to install the package node-cron:

npm install node-cron

Then add the following line to import the package:

const cron = require('node-cron')

After that the usage is as easy as writing:

cron.schedule('*/2 * * * *', () => {
    console.log('run every 2 minutes');
});

Now, just follow the pattern of cron.

If you have any doubts, problems or suggestions, just leave a message.

Source: Sources