node package manager
Easy collaboration. Discover, share, and reuse code in your team. Create a free org ยป


Tree-watcher is a tool for monitoring changes in an entire file tree.

The standard, callback) only watches for changes in a single directory. Tree-watcher can watch an unlimited amount of directories for changes.

Features include

  • Watching subdirs as they are created (so no need to manually add watchers to newly created subdirs of a dir that is already watched)
  • Getting the full path of a changed file as a parameter to the `change`` event handler
  • Adding event handlers at any time (require("tree-watcher").Watcher is an EventEmitter)
  • Throttling change events (tree-watchers keeps track of the event/path combinations that get fired and adds the possibility to throttle these, to prevent a large number of the events firing for a single change)
  • filter out directory names that dont need to be watched (by adding a filter function)


var watcher = require("./treewatcher");

watcher = new watcher.Watcher({
    //filter function return true to allow filename, false to disallow
    //gets the filename, not the full path
    //the default is a function that always returns true
    filter: function(filename) {
        return filename.charAt(0) !== ".";
    //set to 0 to prevent throttling
    throttle: 50

//the Watcher EventEmitter only emits change events, but the event type fired by is passed as the first parameter
//you can alse choose to add the listener inside of the callback for, to make sure no events are fired before every dir is watched
watcher.on("change", function(event, path, watcher) {
    console.log("something has changed");

//the callback is fired when all the (sub)directories are being watched"i:\\", function(err, watcher) {
    if(err) {
        console.log("ERROR: " + err);
    } else {