What is node-watch?
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.
What are node-watch's main functionalities?
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);
});
Other packages similar to node-watch
chokidar
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
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.
watch
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.
#Node-watch
This program is part of Markab(an instant mockup tool, still under development).
The difference bewteen other nodewatch tools is that it does not differentiate event like "rename" or "delete". Once there is a change, the callback function will be triggered.
##Feature
Recursively watch a directory
##Installation
npm install node-watch
Example
var watch = require('node-watch');
watch('somedir', function(filename) {
console.log(filename, ' changed.');
});