:crystal_ball: A globbing fs.watch wrapper built from the best parts of other fine watch libs.
watchwatch-files
Key Metrics
Star Growth
Stars
1.2k
Forks
165
Weekly Growth
—
Issues
62
5001k
Oct 2012Jan 2015May 2017Aug 2019Dec 2021Apr 2024Jul 2026
Artifactsnpmnpm install gaze
README
gaze
A globbing fs.watch wrapper built from the best parts of other fine watch libs. Compatible with Node.js >= 4.x, Windows, macOS, and Linux.
Usage
Install the module with: npm install gaze or place into your package.json
and run npm install.
const gaze = require('gaze');
// Watch all .js files/dirs in process.cwd()
gaze('**/*.js', (err, watcher) => {
// Files have all started watching
// Get all watched files
const watched = watcher.watched();
// On file changed
watcher.on('changed', filepath => {
console.log(filepath + ' was changed');
});
// On file added
watcher.on('added', filepath => {
console.log(filepath + ' was added');
});
// On file deleted
watcher.on('deleted', filepath => {
console.log(filepath + ' was deleted');
});
// On changed/added/deleted
watcher.on('all', (event, filepath) => {
console.log(filepath + ' was ' + event);
});
// Get watched files with relative paths
const files = watcher.relative();
});
// Also accepts an array of patterns
gaze(['stylesheets/*.css', 'images/**/*.png'], () => {
// Add more patterns later to be watched
watcher.add(['js/*.js']);
});
Alternate Interface
const {Gaze} = require('gaze');
const gaze = new Gaze('**/*');
// Files have all started watching
gaze.on('ready', watcher => { });
// A file has been added/changed/deleted has occurred
gaze.on('all', (event, filepath) => { });
Errors
gaze('**/*', (error, watcher) => {
if (error) {
// Handle error if it occurred while starting up
}
});
// Or with the alternative interface
const gaze = new Gaze();
gaze.on('error', error => {
// Handle error here
});
gaze.add('**/*');
In lieu of a formal styleguide, take care to maintain the existing coding style.
Add unit tests for any new or changed functionality. Lint and test your code
using grunt.
Release History
1.1.3 - Fix for Node 10 support (@aredridel). Officially dropping support for Node < 4.
1.1.2 - Prevent more ENOENT errors from escaping (@alexgorbatchev).
1.1.1 - Prevent fs.watch errors from escaping error handler (@rosen-vladimirov). Fix _addToWatched without path.sep (@wyicwx).
1.1.0 - Update to globule@1.0.0 with minimatch >= 3.0.0.
1.0.0 - Revert back to 0.5.2. Drop support for Node.js v0.8. Fix for maxListeners. Update globule to 0.2.0.
0.6.4 - Catch and emit error from readdir (@oconnore). Fix for 0 maxListeners. Use graceful-fs to avoid EMFILE errors in other places fs is used. Better method to determine if pathwatcher was built. Fix keeping process alive too much, only init pathwatcher if a file is being watched. Set min required to Windows Vista when building on Windows (@pvolok).
0.6.3 - Add support for Node.js v0.11
0.6.2 - Fix argument error with watched(). Fix for erroneous added events on folders. Ignore msvs build error 4244.
0.6.1 - Fix for absolute paths.
0.6.0 - Uses native OS events (fork of pathwatcher) but can fall back to stat polling. Everything is async to avoid blocking, including relative() and watched(). Better error handling. Update to globule@0.2.0. No longer watches cwd by default. Added mode option. Better EMFILE message. Avoids ENOENT errors with symlinks. All constructor arguments are optional.
0.5.2 - Fix for ENOENT error with non-existent symlinks [BACKPORTED].
0.5.1 - Use setImmediate (process.nextTick for Node.js v0.8) to defer ready/nomatch events (@amasad).
0.5.0 - Process is now kept alive while watching files. Emits a nomatch event when no files are matching.
0.4.3 - Track file additions in newly created folders (@brett-shwom).
0.4.2 - Fix .remove() method to remove a single file in a directory (@kaelzhang). Fixing “Cannot call method 'call' of undefined” (@krasimir). Track new file additions within folders (@brett-shwom).
0.4.1 - Fix watchDir not respecting close in race condition (@chrisirhc).
0.4.0 - Drop support for Node.js v0.6. Use globule for file matching. Avoid Node.js v0.10 path.resolve/join errors. Register new files when added to non-existent folder. Multiple instances can now poll the same files (@jpommerening).
0.3.4 - Code clean up. Fix “path must be strings” errors (@groner). Fix incorrect added events (@groner).
0.3.3 - Fix for multiple patterns with negate.
0.3.2 - Emit end before removeAllListeners.
0.3.1 - Fix added events within subfolder patterns.