I am using this code to make it run 24 hours after the program is executed but how do I make it run automatically on lets say heroku or something like this? How would I need to change the code?
setInterval(myFunction, 1000*60*60*24)
Thanks!
Edit: I launched this exact code onto heroku as a web worker and it's been running once every 24 hours, just as I wanted. Nothing extra was needed.
I am using this code to make it run 24 hours after the program is executed but how do I make it run automatically on lets say heroku or something like this? How would I need to change the code?
setInterval(myFunction, 1000*60*60*24)
Thanks!
Edit: I launched this exact code onto heroku as a web worker and it's been running once every 24 hours, just as I wanted. Nothing extra was needed.
Share Improve this question edited Aug 10, 2018 at 9:15 static_null asked Jul 12, 2018 at 8:57 static_nullstatic_null 3045 silver badges14 bronze badges 1- you need to create a page where you execute the function and put that page in cron and set the time every 24 hours. – PHP Web Commented Jul 12, 2018 at 8:59
2 Answers
Reset to default 6For this you can use node scheduler npm package https://www.npmjs./package/node-schedule
node scheduler allows you to schedule functions for execution at specific dates, with optional recurrence rules.
var schedule = require('node-schedule');
var j = schedule.scheduleJob('0 0 * * *', function(){
console.log('The answer to life, the universe, and everything!');
});
Above code will execute a cron job when the minute is 0 and hour is 0. basically every day 0:0 in the mid night
use this site to generate formats for the scheduling
setInterval
will only work if the script is kept running 24hrs a day..
otherwise you will need to set up a cron job to call the script for you
this might be a good place to start: https://code.tutsplus./tutorials/scheduling-tasks-with-cron-jobs--net-8800