javascript - how to run task on specified time using node-schedule? -


i want run node task every day 8am using node-schedule package https://www.npmjs.com/package/node-schedule instead of everyday 8am running every minute. correct method can apply rule achieve task ? using node-schedule on linux not sure if format different in case.

cron.js

var cronschedule = require('node-schedule');  module.exports = function cronjob() {     var rule = new cronschedule.recurrencerule();     rule.hour = 8;     var dailyjob = cronschedule.schedulejob(rule, function() {     console.log('testing 8am');             async.eachseries(directories, function (dir, cb1) {                 var dir = __dirname + dir;                 // files directory                 });             }, function (err, fileinfos) {                 if (err) {                     console.info('error', err);                     return;                 }             });     }); } 

if want execute task automatically , recurring can try below code:

var schedule = require('node-schedule'); var schedulefunction = schedule.schedulejob('0 8 * * *', function(){   console.log('yeah ! did.')); }); 

the above code executed daily @ 08:00 am.

or if want execute code once @ start of each quarter try below code:

var myrule = {hour: 0, minute: 0, dayofweek: 1, month: [0, 3, 6, 9]}; var schedulefunction = schedule.schedulejob(myrule, function(){   console.log('will execute every quarter')); }); 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -