Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
node-watch
Advanced tools
The node-watch package is a simple and efficient file system watcher for Node.js. It allows you to monitor changes in files and directories, making it useful for tasks such as live-reloading, automated testing, and more.
Watch a single file
This feature allows you to watch a single file for changes. The callback function is triggered whenever the file is modified.
const watch = require('node-watch');
watch('file.txt', { recursive: false }, function(evt, name) {
console.log('%s changed.', name);
});
Watch a directory recursively
This feature allows you to watch a directory and all its subdirectories for changes. The callback function is triggered whenever any file within the directory or its subdirectories is modified.
const watch = require('node-watch');
watch('directory', { recursive: true }, function(evt, name) {
console.log('%s changed.', name);
});
Filter files to watch
This feature allows you to specify a filter to watch only certain types of files. In this example, only JavaScript files within the directory are monitored for changes.
const watch = require('node-watch');
watch('directory', { filter: /\.js$/ }, function(evt, name) {
console.log('%s changed.', name);
});
Chokidar is a highly efficient and feature-rich file system watcher for Node.js. It supports recursive watching, filtering, and more advanced features like debouncing and throttling. Compared to node-watch, Chokidar offers more configuration options and better performance for large-scale projects.
Gaze is another file watcher for Node.js that supports recursive watching and filtering. It is known for its simplicity and ease of use. While it offers similar functionalities to node-watch, it may not be as performant or feature-rich as Chokidar.
The watch package is a simple file watcher for Node.js. It provides basic functionality for monitoring file changes but lacks some of the advanced features found in Chokidar and node-watch. It is suitable for smaller projects or simpler use cases.
A wrapper and enhancements for fs.watch (with 0 dependencies).
npm install node-watch
var watch = require('node-watch');
watch('file_or_dir', { recursive: true }, function(evt, name) {
console.log('%s changed.', name);
});
This is a completely rewritten version, much faster and in a more memory-efficient way. So with recent nodejs under OS X or Windows you can do something like this:
// watch the whole disk
watch('/', { recursive: true }, console.log);
The events provided by the callback function is either update
or remove
, which is less confusing to fs.watch
's rename
and change
.
watch('./', function(evt, name) {
if (evt == 'update') {
// on create or modify
}
if (evt == 'remove') {
// on delete
}
});
The usage and options of node-watch
is fully compatible with fs.watch.
persistent: <Boolean>
default = truerecursive: <Boolean>
default = falseencoding: <String>
default = 'utf8'filter: <RegExp | Function>
filter using regular expression or custom function.// watch only for json files
watch('./', { filter: /\.json$/ }, console.log);
// ignore node_modules
watch('./', {
recursive: true,
filter: function(name) {
return !/node_modules/.test(name);
}
}, console.log);
The watch function returns a fs.FSWatcher like object as the same as fs.watch
(>= v0.4.0).
var watcher = watch('./', { recursive: true });
watcher.on('change', function(evt, name) {
// callback
});
watcher.on('error', function(err) {
// handle error
});
// close
watcher.close();
// is closed?
watcher.isClosed()
The watcher object is also an instance of EventEmitter. This's a list of methods for watcher specifically:
.on
.once
.emit
.close
.listeners
.setMaxListeners
.getMaxListeners
.isClosed
detect if the watcher is closedWindows, node < v4.2.5
remove
eventwatch(['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
MIT
Copyright (c) 2012-2017 yuanchuan
FAQs
A wrapper and enhancements for fs.watch
The npm package node-watch receives a total of 463,397 weekly downloads. As such, node-watch popularity was classified as popular.
We found that node-watch demonstrated a not healthy version release cadence and project activity because the last version was released 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.