inotifywait-spawn
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}) => {}); {} // kill the subprocess and stop listening to any event {}
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
inotify
Project ?
Why Yet Another 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 = ;const IN_CLOSE_WRITE IN_DELETE IN_MODIFY = INotifyWait; // single fileconst inw = 'test.txt' events: IN_DELETE | IN_CLOSE_WRITE;inw;inw;inw; // folderconst inw = '.' recursive: true events: IN_MODIFY;inw;inw; // multiple files/folders (still one spawned process only)const inw = 'test' 'node_modules' 'build' recursive: true events: IN_MODIFY;inw;inw;
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 accessIN_MODIFY
, to be notified on changesIN_CLOSE_WRITE
, to be notified on end writingIN_CLOSE_NOWRITE
, to be notified on end readingIN_OPEN
, to be notified on file openedIN_MOVED_FROM
, to be notified on files moved fromIN_MOVED_TO
, to be notified on files move toIN_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 pathIN_MOVE_SELF
, to be notified when watched path is movedIN_UNMOUNT
, to be notified on patsh unmountedIN_CLOSE
, to be notified on eitherIN_CLOSE_WRITE
orIN_CLOSE_NOWRITE
IN_MOVE
, to be notified on eitherIN_MOVED_FROM
orIN_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.