How to setup node-schedule for every day at 12am

Anna picture Anna · Oct 27, 2015 · Viewed 10.8k times · Source

I am using node-schedule to schedule my tasks. Now I need to schedule a job everyday at 12am. Below given is the code I am using,

var rule3 = schedule.scheduleJob('00 00 00 * * *', function(){
    console.log('my test job!');
});

This is not working for me.

Any help appreciated. Thanks in advance.

Answer

Furkan Başaran picture Furkan Başaran · Oct 27, 2015

You can use node-cron module simply.

var CronJob = require('cron').CronJob;
var job = new CronJob('00 00 12 * * 0-6', function() {
  /*
   * Runs every day
   * at 12:00:00 AM.
   */
  }, function () {
    /* This function is executed when the job stops */
  },
  true, /* Start the job right now */
  timeZone /* Time zone of this job. */
);

Read docs for more pattern.