Yes. Keep track of the date at which the routine last ran, and compare the current date with that. When they're different, run the routine again and update the last-run date.
For efficiency, it might be best not to do this every second if you can conveniently avoid it.
Also be careful to consider what happens when your app starts.
Best Answer
Fitbit Product Experts Alumni are retired members of the Fitbit Product Expert Program. Learn more
@jaystarkey Yon can use setInterval() to trigger an event in 24 hours time from a specific time.
Author | ch, passion for improvement.
Best AnswerThis makes sense - what is the best way to store the date last ran value? I'm new to development and not sure what persists/how to access persistent data.
Best AnswerPut it in app/index.js?
How would I get this to trigger only at 00:00 every day?
//run once every x hours
let numHours = 24;
setInterval(function(){ doStuff(); }, 1000 * 60 * 60 * numHours);
You can use the fs API to keep track of dateLastRun.
Be careful using setTimeout for this. Timers will be killed whenever the user starts another app (eg, Settings), so your special function may never run.
Also be careful about checking for an exact time. Your clockface might not be running at that exact time.
Best Answer