node package manager

node-watch wrapper of Nodejs


A wrapper to watch files or directories(recursively by default).

npm install node-watch
var watch = require('node-watch');
watch('somedir_or_somefile', function(filename) {
  console.log(filename, ' changed.');
  • Some editors will generate temporary files which will cause the callback function to be triggered multiple times.
  • when watching a single file the callback function will only be triggered one time and then is seem to be unwatched.
  • Missing an option to watch a directory recursively.

This module currently does not differentiate event like rename or delete. Once there is a change, the callback function will be triggered.

recursive:Watch it recursively or not (defaults to true).

followSymLinks: Follow symbolic links or not (defaults to false).

maxSymLevel: The max number of following symbolic links, in order to prevent circular links (defaults to 1).

watch('somedir', { recursive: false, followSymLinks: true }, function(filename) {
  console.log(filename, ' changed.');
watch(['file1', 'file2'], function(file) {

Write your own filter function as a higher-order function. For example:

var filter = function(patternfn) {
  return function(filename) {
    if (pattern.test(filename)) {
// only watch for js files 
watch('mydir', filter(/\.js$/, function(filename) {