1

I would start my schedule whenever my server starts, On cronjob I use @reboot to schedule it, but seems this feature doesn't work on node-cron.

cron.schedule('@reboot', () => {
    console.log('will execute at reboot');
   
});
Khai Dao
  • 55
  • 7

1 Answers1

1

I have the same issue, it's impossible to do with "node-cron" lib. But you can resolve it, by another ways. When u start schedule job in the first time:

  • Write current date to DB
  • Write current date to local file

And you need some controller for checking "if task already done".

var cron = require('node-cron');
var task = cron.schedule('* * * * *', () =>  {
  //check if current date != date from DB/local file => start the job
});

enter image description here