On my server Node.js
I would need to know if the content of a file has been modified, and if it is true, read it and send it by means of socket.io
. The code I have, just reads the content the first time (when the page is reloaded).
init = function (server_created) {
var listen = io.listen(server_created);
listen.sockets.on('connection', function (socket) {
myReadFile(socket);
});
};
function myReadFile(socket) {
fs.readFile(path, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
socket.emit('number', { number: data });
});