Watches a directory for file changes. You know. Like a gargoyle.
Monitor a directory for changes. You can detect file changes, creations, deletions and renames. You know it works because it actually has tests!
npm install gargoyle
There is one export:
gargoyle.monitor(path[, options, callback]).
be a filename (file or directory). IF it's a directory, it'll be traversed
When something changes, it'll emit one of the following events:
modify- when a file is modified
create- when a file is created
delete- when a file is deleted
rename- when a file is renamed (only when options.type === "watch")
Your event listener should be a function that takes one argument: the absolute path of the file that got modified/created/deleted/renamed.
Monitor a directory tree:
var gargoyle = require'gargoyle';gargoylemonitor'/some/dir'if errconsole.errorerr;return;//monitor is an EventEmitter with the following properties:// files is a hash of filename -> FSWatchermonitoron'modify'console.logfilename + ' was modified';;monitoron'delete'console.logfilename + ' was deleted';;monitoron'create'console.logfilename + ' was created';;//only when options.type === "watch"monitoron'rename'console.logfilename + ' was renamed';;;
monitorstopconsole.log'watchers stopped';;//monitor is now worthless
There are a few different options you can pass as an optional
second parameter to
fs.watch. If you're on OS X, or trying to
watch a network directory (e.g. a shared folder in a VM), you'll want
fs.watch is far more efficient, and much faster,
but doesn't work all the time.
var options =type: 'watchFile' //default is 'watch';gargoylemonitor'/some/dir' options//...;
If you use the
watchFile type, you can define the poll interval for
the filesystem (this is part of the
watchFile Node API). The default is
which is 10x as fast as the Node default.
var options =type: 'watchFile'interval: 50 //poll 20 times a second;gargoylemonitor'/some/dir' options//...;
git clone firstname.lastname@example.org:tmont/gargoyle.gitcd gargoylenpm installnpm test
When running the tests, you'll notice the
fs.watchFile tests take much longer.
This is due to the fact that some file systems do not have millisecond resolution,
which means we have to wait at least one second to detect a modification.