node.js - nodejs - every minute, on the minute -
how can wait specific system time before firing ?
i want fire event when seconds = 0, i.e. every minute
while (1==1) { var date = new date(); var sec = date.getseconds(); if(sec===0) { something() } }
you shouldn't that, because while
have blocking operation. also, there better things in javascript platform, using setinterval
/settimeout
functions.
node docs them here.
a quick example of how achieve want:
setinterval(function() { var date = new date(); if ( date.getseconds() === 0 ) { dosomething(); } }, 1000);
for more fine grained control on scheduled processes in node, maybe should checkout node-cron.
Comments
Post a Comment