fs.watch( \'example.xml\', function ( curr, prev ) { // on file change we can read the new xml fs.readFile( \'example.xml\',\'utf8\', function ( err, data ) {
Easiest solution:
const watch = (path, opt, fn) => { var lock = false fs.watch(path, opt, function () { if (!lock) { lock = true fn() setTimeout(() => lock = false, 1000) } }) } watch('/path', { interval: 500 }, function () { // ... })