ogle
v0.1.0
Published
A modern wrapper for fs.watch
Downloads
3
Readme
Ogle
Thin wrapper for fs.watch
with glob-pattern matching.
Example
var watcher = new Ogle(['lib/some-dir/', 'lib/some-dir/*.js']);
watcher.on('add', function(dir, newFile) {
console.log("File %s added to directory %s", newFile, dir);
});
watcher.on('change', function(filePath) {
console.log("File %s changed", filePath);
});
watcher.on('remove', function(filePath) {
console.log("File %s was deleted", filePath);
});
watcher.on('all', function(event, filePath, otherPath) {
switch(event) {
case 'add':
console.log("File %s added to directory %s", filePath, otherPath);
break;
case 'change':
console.log("File %s changed", filePath);
break;
case 'remove':
console.log("File %s deleted", filePath);
break;
}
});
Why?
There are already many wrappers on fs.watch
/fs.watchFile
. Unfortunately, non
of them seemed to be usable without making sacrifices. Ogle chooses the
following advantages:
- glob pattern matching
all/remove/change
events on filesall/add/remove/change
events on directories- Auto-adding of listeners for new files in directories (if we are watching the directory)
- Use of
fs.watch
instead offs.watchFile
. See here for why.
Complete documentation
Coming soon...