Git Product home page Git Product logo

nite-owl's Introduction

nite-owl

Greenkeeper badge 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.