I'm using a index.js file and a check.js file in Node.js. I use check.js to check every 500 ms if some value in my databases has changed. If so, the value of variable currentInput changes. I want to use this variable currentInput in index.js so, that I get the current value of it. I tried searching about in but the solutions I've found don't give me the current value back.
In check.js:
var currentInput;
.
.
.
var check = function(){
pool.query('SELECT someValue FROM table WHERE id=1',function(err,rows){
if(err) throw err;
var newInput = rows[0].someValue;
if(currentInput!=newInput){
currentInput=newInput;
}
console.log('Current value:', currentInput);
});
setTimeout(check, 500);
}
In index.js I'd like to use it something like:
var x = function(currentInput);