How to Setup Node-Schedule for Every Day at 12Am

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.

2

2 Answers

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.

2

For anyone who is stuck on this also check what time your app is operating in. Your app by default might be in Greenwich Mean Time which would definitely make you think your schedule is not working. Toss a console.log(Date.now()) in a convenient location and check. You might just have to adjust the time on your schedule by a couple hours.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest