fsevents
Native access to MacOS FSEvents in Node.js
The FSEvents API in MacOS allows applications to register for notifications of
changes to a given directory tree. It is a very fast and lightweight alternative
to kqueue.
This is a low-level library. For a cross-platform file watching module that
uses fsevents, check out Chokidar.
Installation
npm install fsevents
Usage
const fsevents = require('fsevents');
const stop = fsevents.watch(__dirname, (path, flags, id) => {
const info = fsevents.getInfo(path, flags, id);
});
stop();
The callback passed as the second parameter to .watch
get's called whenever the operating system detects a
a change in the file system. It takes three arguments:
(path: String, flags: Number, id: String) => {}
path
- the item in the filesystem that have been changedflags
- a numeric value describing what the change wasid
- an unique-id identifying this specific event
fsevents.getInfo(path, flags, id): FsEventInfo => {}
The getInfo
function takes the path
, flags
and id
arguments and converts those parameters into a structure
that is easier to digest to determine what the change was.
The FsEventsInfo
has the following shape:
{
"event": "created",
"path": "file.txt",
"type": "file",
"changes": {
"inode": true,
"finder": false,
"access": false,
"xattrs": false
},
"flags": 0x100000000
}
License
The MIT License Copyright (C) 2010-2018 by Philipp Dunkel, Ben Noordhuis, Elan Shankar — see LICENSE file.
Visit our GitHub page and NPM Page