Run console commands after x minutes


#1

Is it possible that I could get a scheduled command (refresh) to run every x seconds for my npm project?


#2

Cron is a tool that allows you to execute something on a schedule. There are many cron-related npm packages available, which you’d have to use alongside a method to keep your project alive. Or you could use a third-party cron service like https://cron-job.org/ or UptimeRobot to trigger a command via a HTTP request and run the command using child_process.exec.


#3

I use UptimeRobot to keep it running but not refreshing (at least i think). I’m not entirely sure about what you said on how to set it up. Is there a tutorial or a more in depth way you could show me how to run the refresh command every X minutes?


#4

thismay be a shitty solution, but this js actually forces the glitch’s main script to restart by throwing an error:

const resetter = setTimeout(function() {
console.log(Restarting Glitch project...);
throw void 0;
}, 5 * (60000));


#5

Add at the top of your JS file:

var child_process = require('child_process');

Then within the route you have defined that UptimeRobot pings add:

child_process.exec('refresh', function(error, stdout, stderr){
	console.log(stdout);
});

#6

It works! Thank you very much!