Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
node-watch
Advanced tools
Readme
A wrapper and enhancements for fs.watch.
npm install node-watch
var watch = require('node-watch');
watch('file_or_dir', { recursive: true }, function(evt, name) {
console.log('%s changed.', name);
});
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
watch('/', { recursive: true }, console.log);
The usage and options of node-watch
are compatible with fs.watch.
persistent: Boolean
(default true)recursive: Boolean
(default false)encoding: String
(default 'utf8')Extra options
filter: RegExp | Function
Return that matches the filter expression.
// filter with regular expression
watch('./', { filter: /\.json$/ });
// filter with custom function
watch('./', { filter: f => !/node_modules/.test(f) });
delay: Number
(in ms, default 200)
Delay time of the callback function.
// log after 5 seconds
watch('./', { delay: 5000 }, console.log);
The events provided by the callback function is either update
or remove
, which is less confusing to fs.watch
's rename
or change
.
watch('./', function(evt, name) {
if (evt == 'update') {
// on create or modify
}
if (evt == 'remove') {
// on delete
}
});
The watch function returns a fs.FSWatcher like object as the same as fs.watch
(>= v0.4.0).
watcher.on('change', function(evt, name) {
// callback
});
watcher.on('error', function(err) {
// handle error
});
watcher.on('ready', function() {
// the watcher is ready to respond to changes
});
// close
watcher.close();
// is closed?
watcher.isClosed()
.on
.once
.emit
.close
.listeners
.setMaxListeners
.getMaxListeners
.isClosed
detect if the watcher is closedWindows, node < v4.2.5
remove
eventMacOS, node 0.10.x
watch(['file1', 'file2'], console.log);
#!/usr/bin/env node
// https://github.com/nodejs/node-v0.x-archive/issues/3211
require('epipebomb')();
var watcher = require('node-watch')(
process.argv[2] || './', { recursive: true }, console.log
);
process.on('SIGINT', watcher.close);
Monitoring chrome from disk:
$ watch / | grep -i chrome
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):
Yuan Chuan 💻 📖 ⚠️ | Greg Thornton 💻 🤔 | Amir Arad 💻 📖 ⚠️ | Gary Burgess 💻 | Peter deHaan 💻 | kcliu 💻 | Hoovinator 💬 |
---|---|---|---|---|---|---|
Steve Shreeve 💻 | Blake Regalia 💻 | Mike Collins 💻 | Timo Tijhof 💻 | Bailey Herbert 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT
Copyright (c) 2012-2018 yuanchuan
FAQs
A wrapper and enhancements for fs.watch
The npm package node-watch receives a total of 376,177 weekly downloads. As such, node-watch popularity was classified as popular.
We found that node-watch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).