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

inotifywait-spawn

v1.0.3

Published

A zero dependencies, 100% code covered, inotifywait wrap based on inotify-tools.

Downloads

18

Readme

inotifywait-spawn

Build Status Coverage Status

Social Media Photo by Omid Kashmari on Unsplash

A zero dependencies, 100% code covered, inotifywait wrap based on inotify-tools and spawn.

API

// listen to events via:
// inw.on(INotifyWait.IN_CLOSE, ({type, path, entry}) => {});
class INotifyWait extends EventEmitter {

  constructor(
    path,               // a single path, or a list of paths, each
                        // representing either a file or a folder
    options = {
      exclude: null,    // a RegExp to exclude files (passed as shell argument)
      include: null,    // a RegExp to include files (passed as shell argument)
                        // Please note `include` option requires inotifywait 3.20+
      persistent: true, // keep watching until .stop()
      recursive: false, // recursive within folders
      events: 0         // one or more events to listen for
                        // if omitted, all events are listened
    }
  ) {}

  // kill the subprocess and stop listening to any event
  stop() {}
}

For RegExp properties, use the /*\.txt/i flag to make it case insensitive.

Please read inotifywait man page to know more about the underlying features offered by include and exclude.

Python 3 Module

In order to run this module in python too, please be sure you have installed the following pip dependency.

sudo pip3 install inotify_simple

Why Yet Another inotify Project ?

Because every other project has either problems compiling code in this or that version of NodeJS, or it's been unmaintained for months or years, with growing amount of bugs.

This project wants to keep it both simple and portable, relying on system inotifywait, avoiding any present or future issue with native/compiled code, making it easy to bring and work with on ARM and other IoT devices too.

Where there is NodeJS, and there is inotifywait, this project might be all you need.

Example

const INotifyWait = require('inotifywait-spawn');
const {IN_CLOSE_WRITE, IN_DELETE, IN_MODIFY} = INotifyWait;

// single file
const inw = new INotifyWait('test.txt', {events: IN_DELETE | IN_CLOSE_WRITE});
inw.on('error', console.error);
inw.on(
  IN_DELETE,
  ({type, path}) => console.log(`${path} removed`)
);
inw.on(
  IN_CLOSE_WRITE,
  ({type, path}) => console.log(`${path} ready to be read`)
);

// folder
const inw = new INotifyWait('.', {recursive: true, events: IN_MODIFY});
inw.on('error', console.error);
inw.on(IN_MODIFY, ({type, path, entry}) => {
  type === IN_MODIFY; // the event type is always available
  console.log(`${entry} modified in ${path}`);
});

// multiple files/folders (still one spawned process only)
const inw = new INotifyWait(
  ['test', 'node_modules', 'build'],
  {recursive: true, events: IN_MODIFY}
);
inw.on('error', console.error);
inw.on(IN_MODIFY, ({type, path, entry}) => {
  console.log(`${entry} modified in ${path}`);
});

Please check test/index.js to see or know more.

Events

Following the list of events supported and available via inotifywait.

These events are better described in the inotify documentation.

  • IN_ACCESS, to be notified on file access
  • IN_MODIFY, to be notified on changes
  • IN_CLOSE_WRITE, to be notified on end writing
  • IN_CLOSE_NOWRITE, to be notified on end reading
  • IN_OPEN, to be notified on file opened
  • IN_MOVED_FROM, to be notified on files moved from
  • IN_MOVED_TO, to be notified on files move to
  • IN_CREATE, to be notified on files creation (folder)
  • IN_DELETE, to be notified on deletion (folder)
  • IN_DELETE_SELF, to be notified on deletion of the watched path
  • IN_MOVE_SELF, to be notified when watched path is moved
  • IN_UNMOUNT, to be notified on patsh unmounted
  • IN_CLOSE, to be notified on either IN_CLOSE_WRITE or IN_CLOSE_NOWRITE
  • IN_MOVE, to be notified on either IN_MOVED_FROM or IN_MOVED_TO

Compatibility

Fully tested on ArchLinux from NodeJS 6 to latest, this should work with every other Linux distribution that offers inotify-tools and inotifywait with it.

Please note that some options might not be available with older versions of inotifywait, like it is for include in current Ubuntu and inotifywait version < 3.20.