I want a task to be executed every month on a specific date as soon as it hits the end point /shcheduleTaskEveryMonth
. Suppose 17th of every month at 4:29pm evening I want to run a job/task
.
And this is the code I am trying to achieve this: Just wanted to be sure if I am doing right please!
PS. This end point gets called once user account is created.
router.get('/shcheduleTaskEveryMonth', function (req, res) {
var schedule = require('node-schedule');
var dateFormated = new Date(Fri Jan 17 2021 16:29:12 GMT+0530 (India Standard Time));
var j = schedule.scheduleJob(dateFormated.getMinutes() +' '+dateFormated.getHours()+' '+dateFormated.getDate() + ' * *', function(){
console.log('Your scheduled job every month');
});
});
How can I achieve that?
UPDATE: I just want to fit the above code simple wise similar to this:
var j = schedule.scheduleJob('42 * * * *', function(){
console.log('The answer to life, the universe, and everything!');
});
Since it's a simple and understandable code I am unable to extract and the add the code likewise. Thanks!