node-watch0.6.2 • Public • Published
A wrapper and enhancements for fs.watch.
npm install node-watch
var watch = ;;
Now it's fast to watch deep directories on macOS and Windows, since the
recursive option is natively supported except on Linux.
// watch the whole disk;
- Some editors will generate temporary files which will cause the callback function to be triggered multiple times.
- The callback function will only be triggered once on watching a single file.
Missing an option to watch a directory recursively.
- Recursive watch is not supported on Linux or in older versions of nodejs.
- Keep it simple, stupid.
The usage and options of
node-watch are compatible with fs.watch.
persistent: Boolean(default true)
recursive: Boolean(default false)
encoding: String(default 'utf8')
filter: RegExp | Function
Return that matches the filter expression.// filter with regular expression;// filter with custom function;
delay: Number(in ms, default 200)
Delay time of the callback function.// log after 5 seconds;
The events provided by the callback function is either
remove, which is less confusing to
The watch function returns a fs.FSWatcher like object as the same as
fs.watch (>= v0.4.0).
// closewatcher;// is closed?watcher
List of methods
.isCloseddetect if the watcher is closed
Windows, node < v4.2.5
- Failed to detect
- Failed to get deleted filename or directory name
MacOS, node 0.10.x
- Will emit double event if the directory name is of one single character.
1. Watch multiple files or directories in one place
2. Customize watch command line tool
#!/usr/bin/env node//;var watcher =processargv2 || './' recursive: true consolelog;process;
Monitoring chrome from disk:
$ watch / | grep -i chrome
3. Got ENOSPC error?
If you get ENOSPC error, but you actually have free disk space - it means that your OS watcher limit is too low and you probably want to recursively watch a big tree of files.
Follow this description to increase the limit: https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit
Thanks goes to these wonderful people (emoji key):
💻 📖 ⚠️
💻 📖 ⚠️
This project follows the all-contributors specification. Contributions of any kind welcome!
Copyright (c) 2012-2018 yuanchuan