Modern file watcher for nodejs
- Watch a directory and his subdirectories for changes
- Filter method to exclude files or directories
npm install file-watcher
var Watcher = require('file-watcher');
var watcher = new Watcher({
root: __dirname,
filter: function(filename, stats) {
// only watch those files
if(filename.indexOf('.styl') != -1) {
return true;
}
else {
return false;
}
}
});
watcher.on('...', function() { /* Watcher is an EventEmitter */ });
watcher.watch(__dirname, function(err){
if (err){
console.log(err);
}
});
- opts.root : Directory to watch
- opts.filter : callback to filter filename or by fs.Stat
- filename : filename relative to the root of the watched tree
- stats : a fs.Stat object
Return true to include this file or directory and their children. Return false to exclude them.
- dir : Directory to watch
- cb : (optional) callback fired then the watch has started. As error object may be passed as the first argument if there was a problem.
Start watching the directory tree
- event.oldStats : null
- event.oldPath : null
- event.newStats : a fs.Stat object
- event.newPath : created filename relative to the root of the watched tree
- event.oldStats : last fs.Stat object
- event.oldPath : current filename relative to the root of the watched tree
- event.newStats : current fs.Stat object
- event.newPath : current filename relative to the root of the watched tree
- event.oldStats : last fs.Stat object
- event.oldPath : deleted filename relative to the root of the watched tree
- event.newStats : null
- event.newPath : null
- type : event type
- event : see corresponding event type
- err : unhandled error
- Add unit tests
- Handle rename
- ?
- 2013-06-11 : first working version