daanlib/tree-watcher — Issue #2: 'on' event callback signature
Author: alexyoung
Created: 2011-12-21 10:36:20+00:00
State: open

Your example reads like this:

watcher.watch("C:\\myDir", function(err, watcher) {
if(err) {
console.log("ERROR: " + err);
} else {
console.log("DONE");
}
});

When I try that (in Mac OS X) the callback doesn't follow the same signature. Whenever any change happens (file creation, deletion, change) the `err` value is a string set to `rename`, and the second parameter is the directory name, then the third parameter is the object for a `Watcher`.

This is the code I tried it with:

var treeWatcher = require('tree-watcher')
, watcher;

watcher = new treeWatcher.Watcher({
filter: function(filename) {
return filename.charAt(0) !== '.';
}
, throttle: 50
});

watcher.on('change', function(err, w) {
console.log('change args:', arguments);
if (err) {
console.error('Error:', err);
} else {
console.log('Watcher state:', w);
}
});

watcher.watch('/Users/alex/Desktop/watch', function() {
console.log('Args:', arguments);
});