Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.npmignore
LICENSE
README.md
package.json

README.md

DirectoryWatcher

A directory watcher that keeps an in memory list of the files in the directory, perfoming diffs on them when events arise from the underlying FSWatcher, which doesn't always reports back the files that are related to an event.

The API also provides "nicer" events using the EventEmitter API: "change", "add", "delete". (currently "change" doesn't function properly if the underlying watcher does not return the changed filename)

Install

    npm install directory-watcher

create a watcher using FSWatcher

var DirectoryWatcher = require('directory-watcher');

DirectoryWatcher.create('/path/to/somewhere', function(err, watcher) {
    watcher.once('change', function(files) {
        console.log('will fire once');      
    });

    watcher.on('delete', function(files) {
        console.log('%s deleted', files);
    });

    watcher.on('add', function(files) {
        console.log('%s added', files);
    });
});

using without FSWatcher or with external FSWatcher (untested)

var DirectoryWatcher = require('directory-watcher');

DirectoryWatcher.createEx('/path/to/somewhere', function(err, watcher) {
    var onFileEvent = watcher.listener();
    onFileEvent('rename', undefined);
});

or

var DirectoryWatcher = require('directory-watcher');
var fs = require('fs');

DirectoryWatcher.createEx('/path/to/somewhere', function(err, watcher) {
    fs.watch(path, watcher.listener(), { persistent: false });
});

note that watcher.kill() will only clear the internal files cache in this instance

Something went wrong with that request. Please try again.