npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

io-event-reactor

v1.0.0-beta.5

Published

Module for conditionally reacting to watches and monitors on filesystem events by executing customizable plugins

Downloads

4

Readme

io-event-reactor

Node.js module for reacting to filesystem events by invoking plugins that match configurable evaluators.

NPM

How it works

The basic concept is this; you have a monitor that listens for IO events for particular paths on the filesystem. As these IO events occur, they are passed on to one or more evaluators to decide whether or not the IoEvent should be reacted to by one or more configured reactors. The entire latter sequence is encapsulated in an IoReactor instance that manages the flow between the three described components.

)

With this module, you construct and configure a single IoReactorService which can manage and contain one or more IoReactor instances, as many as you wish, providing for lots of flexibility for reacting to filesystem events.

When you configure the IoReactorService and its IoReactor instances, you specify which plugins you would like to use to fulfill the monitor and reactor roles. For evaluators you simply provide one or more functions which evaluate whether or not an IoEvent should be passed on to one or more reactors.

Requirements

Install

npm install io-event-reactor

Usage

Usage is pretty straight forward, one of the better starting points to to review one of the following apps:

Below is an end-to-end simple sample:

  1. mkdir myapp/
  2. mkdir -p /tmp/myapp
  3. npm install io-event-reactor
  4. npm install io-event-reactor-plugin-chokidar
  5. vi myapp.js
var IoReactorService = require("io-event-reactor");
var EvaluatorUtil = require('io-event-reactor/ioReactor').EvaluatorUtil;

// IoReactorService configuration
var config = {
  ioReactors: [
        {   id: "reactor1",
            monitor: {
                plugin: "io-event-reactor-plugin-chokidar",
                config: {
                    paths: "/tmp/myapp",
                    options: {
                        alwaysStat: false,
                        awaitWriteFinish: {
                            stabilityThreshold: 200,
                            pollInterval: 100
                        },
                        ignoreInitial:true
                    }
                }
            },

            /**
            *
            * evaluators - REQUIRED array[] of one or more config objects, each containing the following properties
            *   - evaluator: function(ioEventType, fullPath, optionalFsStats, optionalExtraInfo), if function returns 'true' all attached reactors will be invoked. If false, nothing will happen. See the 'Evaluators' class for methods that will generate an applicable function for simple use-cases.
            *   - reactors: array[] of reactor ids that should be invoked if the 'evaluator' function returns 'true'
            */
            evaluators: [
                {
                    // see ioReactor.js (EvaluatorUtil class) for some helper function generators for simple use cases
                    evaluator: EvaluatorUtil.regex(['add','change','unlink','unlinkDir','addDir'],'.*bitsofinfo.*','ig'),
                    reactors: ['code1']
                }
            ],

            reactors: [
                { id: "code1",
                  plugin: "./default_plugins/code/codeReactorPlugin",
                  config: {
                      codeFunction: function(ioEvent) {
                          return new Promise(function(resolve,reject){
                             console.log("I just reacted to an IoEvent! type: " +ioEvent.eventType + " file: " +ioEvent.fullPath);
                          });
                      }
                  }
                }
            ]
        }
   ]
};

// start the reactor
var reactor = new IoReactorService(config);
  1. node myapp.js
  2. In another shell: touch /tmp/myapp/bitsofinfo.txt
  3. You should see output: I just reacted to an IoEvent! type: add file: /tmp/myapp/bitsofinfo.txt

For more info on configuration options see the JSDoc in ioReactorService.js and ioReactor.js

Plugin support

This module is extensible via plugin contracts for both monitors and reactors. You can pretty much customize it to integrate it with anything you want. See io-event-reactor-plugin-support for more details on creating plugins.

Monitor plugins

Reactor plugins

Default Plugins

The plugins below are simple and just come with this module by default.

  • code - Permits arbitrary execution of javascript, to use: ./default_plugins/code/codeReactorPlugin
  • logger - Log reactions to monitored events, to use: ./default_plugins/logger/loggerReactorPlugin

External module plugins

Unit tests

To run the unit tests go to the root of the project and run the following.

mocha test/all.js