5.0.5 • Published 2 years ago

nite-owl v5.0.5

Weekly downloads
615
License
Apache-2.0
Repository
github
Last release
2 years ago

nite-owl

package version build status

You need to watch a directory for changes, but don't want to be notified all the time? Try nite-owl.

Who watches the Nite Owl?

Before you ask: No, we didn't implement all this hairy file watching business ourselves. We simply use chokidar.

Using nite-owl basically comes down to this:

let watch = require("nite-owl");

watch(myFavoriteDirectories). // either a single directory path or an array thereof
    on("edit", myFavoriteFunction).
    on("error", myErrorFunction);

Whenever one of the files in any of myFavoriteDirectory changes, myFavoriteFunction will be invoked with the paths of all files which changed within a short interval.

This notification is debounced: You only get notified at most once every 50 milliseconds. You can adjust that value by providing a second argument to the watch function.

The error callback will be called, when watching the files resulted in an error. The most common error is the TooManyFilesError (it has the code ERR_TOO_MANY_FILES). It occurs on Linux when you watch too many files. In this case you have to either increase the inotify limits or choose to watch less files. An error handler could look like this:

watch(myFavoriteDirectories).
    on("error", err => {
        if(err.code === "ERR_TOO_MANY_FILES") {
            console.error("Watching too many files");
            process.exit(1);
        } else {
            throw err;
        }
    });

The process can also be terminated programmatically:

let watcher = watch(…);
…
watcher.terminate();

License

Licensed under Apache 2.0.

5.0.5

2 years ago

5.0.4

5 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.0.0

5 years ago

3.3.2

6 years ago

3.3.1

6 years ago

3.3.0

6 years ago

3.2.0

6 years ago

3.1.0

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago