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 🙏

© 2026 – Pkg Stats / Ryan Hefner

nd-file-notify

v1.0.1

Published

File monitoring utility that tracks filesystem changes (creation and deletion of directories) and reports them in real time via a callback.

Readme

Directory Monitor

File monitoring utility that tracks filesystem changes (creation and deletion of directories) and reports them in real time via a callback.


Overview

The monitor maintains an internal event loop (epoll-based) and allows dynamically adding or removing directories to watch. It reports directory-level events with normalized paths, even when parent directories are removed recursively.

Key characteristics demonstrated by the output:

  • Multiple watch roots can be added and removed at runtime
  • The active watch list is queryable
  • Recursive directory creation and deletion events are detected
  • Deleted path segments are explicitly marked as (deleted) when intermediate directories disappear

Usage

const {creat,destroy} = require("nd-file-notify");

const o = creat((ftype, event_name, path)=>{
            //ftype        : dire |  file
            //event_name   : created | deleted | modified| moved_from | moved_to | attr
            console.log({ftype, event_name, path})
});
o.start();

.....

o.destroy(); //MUST when you exist

getter

 .ftypes
 .event\_names

 .fan\_fd
 .epfd
 .stop\_fd

accessor

.cb
.cb = (ftype, event\_name, path)=>{} 

methods;

.start()
.stop()


.has(path);
.add(path);
.del(path);
 
.list();    

ftype

["dire","file"]

event_names

[
  '', 'created',
  'deleted', 'modified',
  'moved',   'moved',
  'attr',    'created',
  'deleted', 'modified',
  'moved',   'moved',
  'attr'
]

Monitor State

Example monitor initialization output:

Monitor [{
  "ptr": "0x38c51390",
  "fan_fd": 17,
  "epfd": 18,
  "stop_fd": 19
}] {
  _cb: [Function: cb],
  active: true
}

This indicates:

  • fan_fd: fanotify file descriptor
  • epfd: epoll file descriptor
  • stop_fd: internal shutdown signal
  • _cb: user-defined callback
  • active: monitor is running

Managing Watch Directories

Initial Watch List

--- Current Watch List ---
(empty)
--------------------------
[]

No directories are being monitored initially.

Adding Directories

[System] Watch added: /tmp
[System] Watch added: /root

Resulting watch list:

--- Current Watch List ---
 - /root
 - /tmp
--------------------------
[ '/root', '/tmp' ]

Removing a Directory

[System] Watch removed: /root

Updated watch list:

--- Current Watch List ---
 - /tmp
--------------------------
[ '/tmp' ]

Event Model

Each filesystem event is delivered to the callback as a structured object:

{
  ftype: 'dire',
  event_name: 'created' | 'deleted',
  path: '/absolute/path'
}
  • ftype: currently always 'dire' (directory)
  • event_name: event type
  • path: resolved absolute path

Deletion Events

When directories are removed recursively, the monitor reports deletions from deepest to shallowest levels. If an intermediate directory disappears before its children are fully resolved, it is annotated with (deleted).

Example:

{
  ftype: 'dire',
  event_name: 'deleted',
  path: '/tmp/watch/aaa/bbb (deleted)/ccc'
}

This means bbb was deleted before ccc could be fully traversed.

More examples:

{ ftype: 'dire', event_name: 'deleted', path: '/tmp/watch/aaa' }
{ ftype: 'dire', event_name: 'deleted', path: '/tmp/watch' }

Creation Events

Recursive directory creation is reported in order, from parent to child:

{ ftype: 'dire', event_name: 'created', path: '/tmp/watch' }
{ ftype: 'dire', event_name: 'created', path: '/tmp/watch/11' }
{ ftype: 'dire', event_name: 'created', path: '/tmp/watch/11/22' }
{ ftype: 'dire', event_name: 'created', path: '/tmp/watch/11/22/33' }
{ ftype: 'dire', event_name: 'created', path: '/tmp/watch/11/22/33/44' }

And similarly for other directory trees:

{ ftype: 'dire', event_name: 'created', path: '/tmp/watch/aaa/bbb/ccc/ddd' }

Notes

  • Only directories are shown in this output; file events may be unsupported or intentionally filtered.
  • The monitor is resilient to deep directory trees and rapid recursive changes.
  • Output order reflects actual kernel event delivery, not synthetic ordering.

Typical Use Cases


License