it's my first time with JS and I'm doing task for my class. How can I set automatic refresh every n seconds in this type of code? Found some examples but none of them worked for me.
var http = require('http');
var port = 8080;
function lightSensor() {
var data = Math.random().toFixed(2)
console.log("Light sensor: " + data);
return data;
}
http.createServer(function(req,res){
res.writeHeader(200, {'Content-Type': 'application/json'});
res.write('{"Light sensor" : ' + lightSensor() + '}');
res.end();
}).listen(port);
console.log('Server listening on: http://localhost:' + port);
process.on('SIGINT', function () {
process.exit();
});