Categories
Categories
Shreya kumari
by on May 23, 2018
133 views
Cron Jobs are used for scheduling tasks to run on the server.CRON Jobs are most commonly used method to automate tasks on Server. In this article, we will see how to schedule JOBS in Node.js. We are going to use node-schedule package for scheduling JOBS.
node-schedule is a light cron-like scheduler Package for Node JS.
Installing node-schedule
npm install node-schedule
Setting up Scheduler
var scheduler = require('node-schedule');
var rule = new scheduler.RecurrenceRule();
rule.hour = 7
rule.dayOfWeek = new schedule.Range(0,6)
var dailyJob = schedule.scheduleJob(date, function(){
console.log('I run on days at 7:00');
});
scheduler.scheduleJob(rule,task);
Canceling a Scheduled Job on Node
dailyJob .cancel();
You can read more about node-schedule package from https://github.com/node-schedule/node-schedule
Also, Read Node js interview questions from https://www.onlineinterviewquestions.com/node-js-interview-questions/
2 LIKED
2 people like this.