joyent/node — Issue #2126: fs.watch detecting two change events on each write
Author: TrevorBurnham
Created: 2011-11-16 00:21:43+00:00
State: open

It seems that `fs.watch` detects every write to a file as two separate changes: one immediate, and one delayed by anywhere from 400ms to 4 seconds. I've run this test case against Node 0.6.1 under the latest OS X:

var fs = require('fs');
var startDate = new Date();
var fswatcher = fs.watch('foo.txt', function(event) {
console.log(event, new Date() - startDate);
});
fs.writeFile('foo.txt', 'foo bar baz', function(){
console.log('Write complete');
});

I consistently see two change events, e.g.

change 33
Write complete
change 2259