Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fs.watch fired twice when I change the watched file

 fs.watch( 'example.xml', function ( curr, prev ) {    // on file change we can read the new xml    fs.readFile( 'example.xml','utf8', function ( err, data ) {      if ( err ) throw err;      console.dir(data);      console.log('Done');    });  }); 

OUTPUT:

  • some data
  • Done X 1
  • some data
  • Done X 2

It is my usage fault or ..?

like image 380
avicennasoftwarelabs Avatar asked Oct 19 '12 16:10

avicennasoftwarelabs


1 Answers

The fs.watch api:

  1. is unstable
  2. has known "behaviour" with regards repeated notifications. Specifically, the windows case being a result of windows design, where a single file modification can be multiple calls to the windows API
like image 185
Pero P. Avatar answered Oct 01 '22 04:10

Pero P.