An event wrapper for fs.watch(), with support for recursive directories
An event wrapper for fs.watch(), with support for recursive directories.
fs.watch() API is not 100% consistent across platforms,
and is unavailable and less reliable in some situations.
Due to the behavior of
fs.watch(), if you want to read the updated file content
in the event listener, please delay a few milliseconds manually.
npm install watch.io
WatchIO object inherits
events.EventEmitter, so use it in an event-style.
var WatchIO =watcher =;// Watch a folder recursivelywatcher;// Listen on file creationwatcher;// Listen on file updatingwatcher;// Listen on file removalwatcher;// Listen on file refreshment// The `refresh` event emits when the WatchIO scans a folder// which usually occur by calling the `.watch(path)` functionwatcher;// Listen on whatever the file changes// the `type` parameter can be any one of: 'create', 'update', 'remove', 'refresh'watcher;// Listen on whatever the fs.FSWatcher throws an error// the `err` parameter is the same as the one from 'error' event of fs.FSWatcherwatcher;// Stop watching the folder/filewatcher;
Removing event listeners is the same as the way in
events.EventEmitter of node.js.
// As:watcher;watcher;watcher;watcher;watcher;watcher;// Or:watcher;
Initialize WatchIO object with config:
var WatchIO =watcher =delay: 100;
delaynumber Delay time(ms) for suppress duplicated notify messages from fs.watch(), defaults to 100(ms), set to 0 to disable it.
Due to the behavior of the underlying API, there have some issues still suck on Windows platform.
Removing folders will emit an 'EPERM' error. No solutions so far.
Creating folders manually on Windows, sometimes emit an uncaught 'EBUSY' error. This can be fixed by setting a delay milliseconds longer than 100ms in the Watch.IO options.
The MIT License (MIT)
Copyright (c) 2009-2016, DJ-NotYet email@example.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.