In a Node application I have a function that runs every 30 seconds.
It prints to the console using moment().day()
. I let it run over night and expected it to notice that the day is now 5
instead of 4
signifying that it is now Friday rather than Thursday. It continued to print 4
when I checked this morning. Why would this be?
Here is a jsfiddle https://jsfiddle.net/9ya2auzy/2/
function checkTheDay(){
setTimeout(function(){
document.getElementById("out").innerHTML = moment().day();
checkTheDay();
}, 2000);
}
checkTheDay();
It will output the current day every 2 seconds. If the page is left open, it should run over night and then print the next number, 6
(at the time of writing) rather than the current ouput 5
(at the time of writing).