Monday 11 June 2018

How to create a monitoring server and display the differences?

Basically, I am creating a server that monitors JSON array outputs from another server and display the differences the next time it gets a new value. The server uses axios to get the "currPoll" with timer setInterval is 10 seconds to get the current value and compare to the previous value (prevPoll).I tried using global variables but I am unable to preserve the previous array to make a comparison to the current array. Can someone point out how do i keep "prevPoll" so I can reuse it to compare with "currPoll" and display the differences every 10 seconds?prevPoll = [ ]; currPoll = [ ]; differences = [ ] ;function getValidPoll() { axios.get('localhost:1050') { .then(function(response){ currPoll = response.data; return currPoll; }).then((currPoll) { for(var i in currPoll) { if(!prevPoll.hasOwnProperty(key) || currPoll[key] !== prevPoll[key]) { differences[key] = currPoll[key]; } } return differences; }).catch(error => { console.log(error); }); }var interval = setInterval(getValidPoll, 10000);

Submitted June 11, 2018 at 01:05PM by markpsp

No comments:

Post a Comment