Simple Watcher
A simple recursive directory watcher.
But why?
I know there's plenty of them out there, but most don't seem to care about the recursive
option of Node's fs.watch()
, which significantly improves performance on the supported platforms, especially for large directories.
Features:
- Dead simple and dead lightweight.
- No dependencies.
- Leverages the
recursive
options on OS X and Windows; uses a fallback for other platforms. - Takes care of WinAPI's
ReadDirectoryChangesW
double reporting.
Usage
Command line
Usage:
simple-watcher path1 [path2 path3 ...] [--shallow]
JavaScript
const watch = require('simple-watcher')
watch('/path/to/foo', filePath => {
console.log(`Changed: ${filePath}`)
})
watch(['/path/to/foo', '/path/to/bar'], {shallow: true}, filePath => {
console.log(`Changed: ${filePath}`)
})
Caveats
When watching over files rather than directories, the fs.watchFile()
is used. This is to provide a polling fallback in cases where directory watching is problematic (e.g. Docker).