file-watcher
Modern file watcher for nodejs- Watch a directory and his subdirectories for changes
- Filter method to exclude files or directories
Installation
npm install file-watcher
Usage
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();
constructor new Watcher(opts)
callback filter(filename, stats)
Return true to include this file or directory and their children. Return false to exclude them.
method watcher.watch()
Start watching the directory treeevent create (event)
- event.oldStats : null
- event.oldPath : null
- event.newStats : a fs.Statfs.Stat object
- event.newPath : created filename relative to the root of the watched tree
event change (event)
- event.oldStats : last fs.Statfs.Stat object
- event.oldPath : current filename relative to the root of the watched tree
- event.newStats : current fs.Statfs.Stat object
- event.newPath : current filename relative to the root of the watched tree
event delete (event)
- event.oldStats : last fs.Statfs.Stat object
- event.oldPath : deleted filename relative to the root of the watched tree
- event.newStats : null
- event.newPath : null
event any (type, event)
- type : event type
- event : see corresponding event type
event error (err)
- err : unhandled error
TODOs
- Add unit tests
- Handle rename
- ?
History
- 2013-06-11 : first working version