Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Yet another NodeJS library for watching FS trees
CoffeeScript JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
lib
src
.gitignore
Cakefile moved build dir to lib cause build is irgnored by npm - see npm/npm#496
LICENSE.txt
README.md moved build dir to lib cause build is irgnored by npm - see npm/npm#496
index.js add index.js
package.json

README.md

watch-tree

...is yet another NodeJS FS-watching library. If it happens to suit your needs better than the others, enjoy!

The current implementation maintains a ring of paths (both files and dirs), and stats the next one every (--sample-rate=) ms.

More efficient implementations will be added eventually, including inotify (for Linux) and FSEvents (for Mac), with the appropriate one being compiled at (npm install)-time.

Your code won't notice the difference when that happens, but your battery life might.

Installing

npm install watch-tree

Command-line tool

Usage

watch-tree [[relative_]path]
    [--ignore=(...regex...)]
    [--match=(...regex...)]
    [--sample-rate=(...ms...)]

Example

cd ~/repos/watch-tree; watch-tree '--ignore=/\.'

stdout:

...
["filePreexisted","/Users/a/repos/node-watch-tree/README.md","2011-01-14T18:34:56.000Z"]
["allPreexistingFilesReported"]
["fileModified","/Users/a/repos/node-watch-tree/README.md","2011-01-14T18:35:05.000Z"]
["fileCreated","/Users/a/repos/node-watch-tree/foo","2011-01-14T18:35:07.000Z"]
["fileDeleted","/Users/a/repos/node-watch-tree/foo"]

NodeJS

The watcher returned by .watchTree is a NodeJS EventEmitter instance.

watcher = require('watch-tree').watchTree(path, {'sample-rate': 5});
watcher.on('fileDeleted', function(path) {
    console.log("Quoth the walrus: Noooo, they're deleting mah " + path + "!");
});

Events

Event Callback Arguments
filePreexisted path, stats
allPreexistingFilesReported
fileCreated path, stats
fileModified path, stats
fileDeleted path

...where stats is a NodeJS fs.Stats instance.

Developing

# Install
git clone https://github.com/tafa/node-watch-tree.git; cd node-watch-tree
npm link

# Develop
coffee -cwlo lib src

# Push
cake build && cake test
Something went wrong with that request. Please try again.