Fast and reliable files watcher.
Fast and reliable Node.js files watcher.
- It's fast, because it wraps fs.watch which does not use pooling.
- It's reliable, because it supports only that behavior that works reliable across all OS's.
There are zilions Node.js file watchers. No one is perfect. The most feature rich is probably gaze, but it burns CPU because it uses pooling fs.watchFile. This watcher uses only fs.watch so it has limited functionality (can't detect deleted files), but it works. And it's fast even for thousands of files. Read more here and here.
Create a watcher to watch all files in the directories "foo" and "bar":
// Relative path to file that was changed or createdconsole.logfilefilepath;// File Extensionconsole.logfileextension;var esteWatch = require'este-watch';var watcher = esteWatch'foo' 'bar' onWatch;// Start the watcherwatcherstart
A third argument can be passed to the esteWatch function to specify options.
Three options are available:
- filter: (RegExp) only fire watcher callback for files where the full relative filepath matches this pattern
- ignoreFiles: (RegExp) prevent watcher callback from firing for files where the full relative filepath matches this pattern
- ignoreDirectories: (RegExp) prevent watcher from even starting for directories where the full relative directory path matches this pattern
esteWatch'foo' 'bar' onWatchfilter: /\.js$/ignoreFiles: /\.min\.js$/ignoreDirectories: /node_modules/start;