-1

Hello I'm using a node JS server that is watching file changes from mounted folder but it doesn't detect the changes because the files should be a local files.

Can anybody ask me a solution because I should do it like this onde node js who detects changes files from another pc

there is the code:

var express = require('express');  
var app = express();  
var server = require('http').Server(app);  
var io = require('socket.io')(server);
var fs = require('fs');
var watch = require('node-watch');

var last={  
  id: "1",
  content:""
}
io.on('connection', function(socket) {  

  console.log('Some one is connected by Sockets');
  socket.emit('telegrama', lastGDC);


});

watch('data/position.csv', { recursive: true }, function(evt, name) {
    console.log('%s changed.', name);
    /* last.content=fileChangedContent;*/
    io.sockets.emit('telegrama', last);

});
server.listen(8080, function() {  
    console.log("running server ://localhost:8080");
});
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
  • The question is missing an important detail. How is the data folder mounted? – Lorenz Meyer Jun 10 '17 at 08:24
  • @LorenzMeyer my guess would be sshfs – robertklep Jun 10 '17 at 11:03
  • Perhaps you can use [`fs.watchFile`](https://nodejs.org/api/fs.html#fs_fs_watchfile_filename_options_listener), which uses polling to check for changes, instead of relying on mechanisms that may not work for (all) mounted file systems. – robertklep Jun 10 '17 at 11:04
  • Yes lorenz I am using sshfs and now with fs.watchFile is working the event but not detect all changes. It's like even 5 changes in 10 seconds detect only 3 – ORIOL DOMINGO ADELL Jun 12 '17 at 07:40

1 Answers1

0

It's working now the problem was in watch that no detect my mounted files but when i worked with watchFile it works by default watchFile is working with interval of 5007 milliseconds and you can set it in options like this:

watchFile('path/file.txt', { recursive: true,interval:2000 },          
});