1

Only need a simple alternative to weekly job scheduling in Node

I came across this and this, but I don't understand how can i use them in my case.

I simple want to execute function executeMeWeeklyAt1200PMMonday(). Is there a simple an easier way to do it? If not then can someone help me using any existing library to achieve this?

2 Answers2

3

You can use the library cron like this:

var CronJob = require('cron').CronJob;
var job = new CronJob('0 0 12 * * 1', executeMeWeeklyAt1200PMMonday, null, true, 'America/Los_Angeles');

That will call the function executeMeWeeklyAt1200PMMonday every Monday at noon in Los Angeles. Change 'America/Los_Angeles` to the timezone you want to use.

Paul
  • 139,544
  • 27
  • 275
  • 264
1

Hey you can easly use this : https://github.com/kelektiv/node-cron

var CronJob = require('cron').CronJob;
var job = new CronJob('00 05 08 * * 0', function() {
  /*
   * This function is executed every Synday at 8:05
   */
   executeMeWeeklyAt1200PMMonday();
  }, function () {
    /* This function is executed when the job stops */
  },
  true, /* Start the job right now */
  timeZone /* Time zone of this job. */
);
Diptox
  • 1,809
  • 10
  • 19