I need to create a function that can display a metric pulled at different hours of the day from an outside source one week ago. The way I have my server currently set up is usin
Did you try use an external module, like node-schedule? The periodic issues may be easier with it. With this module you may, for example, execute some task periodically, setting the intervall you want, say, 1 week.
Another point to consider is the timezone. It may be a problem when you commit the code to server in another tz and it fails your counts. moment-timezone module is a good resource.
Something along these lines might help. Applying node cron to set the interval:
var net = require('net');
var port = Number(process.env.PORT || 3000)
var timeInMs = Date.now();
var weekInMs = 604800000;
var server = net.createServer(function (socket) {
//if time in Ms is time from first ping to now then...
socket.end(timeInMs + '\r\n');
});
server.listen(port);
The cron job:
var CronJob = require('cron').CronJob;
new CronJob('* * * * * *', function() {
console.log('You will see this message every second');
}, null, true, 'time zone');