Sane aims to be fast, small, and reliable file system watcher.
I've been driven to insanity by node filesystem watcher wrappers. Sane aims to be fast, small, and reliable file system watcher. It does that by:
fs.watchby default and sensibly works around the various issues
fs.watchis not reliable you have the choice of using the following alternatives:
$ npm install sane
Don't worry too much about choosing the correct mode upfront because sane maintains the same API across all modes and will be easy to switch.
watchmanwould be the most reliable mode
Watches a directory and all it's descendant directories for changes, deletions, and additions on files and directories.
var watcher = sane'path/to/dir' glob: '**/*.js' '**/*.css';watcheron'ready' console.log'ready' ;watcheron'change' console.log'file changed' filepath; ;watcheron'add' console.log'file added' filepath; ;watcheron'delete' console.log'file deleted' filepath; ;// closewatcherclose;
glob: a single string glob pattern or an array of them.
poll: puts the watcher in polling mode. Under the hood that means
watchman: makes the watcher use watchman.
dot: enables watching files/directories that start with a dot.
The default watcher class. Uses
fs.watch under the hood, and takes the same options as
The watchman watcher class. Takes the same options as
The polling watcher class. Takes the same options as
sane(options, dir) with the addition of:
Emits the following events:
All events are passed the file/dir path relative to the root directory
readywhen the program is ready to detect events in the directory
changewhen a file changes
addwhen a file or directory has been added
deletewhen a file or directory has been deleted
This module includes a simple command line interface, which you can install with
npm install sane -g.
Usage: sane <command> [...directory] [--glob=<filePattern>] [--poll] [--watchman] [--dot] [--wait=<seconds>]OPTIONS:--glob=<filePattern>A single string glob pattern or an array of them.--poll, -pUse polling mode.--watchman, -wUse watchman (if available).--dot, -dEnables watching files/directories that start with a dot.--wait=<seconds>Duration, in seconds, that watching will be disabledafter running <command>. Setting this option willthrottle calls to <command> for the specified duration.
It will watch the given
directory and run the given every time a file changes.
sane 'echo "A command ran"'
sane 'echo "A command ran"' --glob='**/*.css'
sane 'echo "A command ran"' site/assets/css --glob='**/*.css'
sane 'echo "A command ran"' --wait=3
sane 'echo "A command ran"' -p
The CLI was originally based on the watch CLI. Watch is licensed under the Apache License Version 2.0.