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

metawatch

v2.0.0

Published

Recursive file and directory watcher for Node.js with debouncing, event deduplication, and zero dependencies.

Downloads

1,017

Readme

Metawatch

ci status snyk npm version npm downloads/month npm downloads license

Recursive file and directory watcher for Node.js with debouncing, event deduplication, and zero dependencies.

Features

  • 🔍 Recursive directory watching: auto and recursive watches subdirectories
  • 🔄 Dynamic directory management: auto adds new directories and removes deleted ones
  • Event deduplication: prevents duplicate events for the same file changes
  • 🎯 Debounced events: batches multiple changes within a configurable timeout
  • 📦 Zero dependencies, uses only Node.js built-in modules
  • 🎭 EventEmitter API: simple event-driven interface

Installation

Requires Node.js 18 or later.

npm i metawatch

Quick Start

const metawatch = require('metawatch');

const watcher = new metawatch.DirectoryWatcher({ timeout: 200 });
watcher.watch('/path/to/directory');

watcher.on('change', (fileName) => {
  console.log('File changed:', fileName);
});

watcher.on('delete', (fileName) => {
  console.log('File deleted:', fileName);
});

API Reference

DirectoryWatcher

new DirectoryWatcher(options);

Options:

  • timeout (number, optional): Debounce timeout in milliseconds. Default: 5000

Methods:

  • watch(targetPath) - Start watching directory recursively
  • unwatch(targetPath) - Stop watching directory
  • close() - Stop all watchers, clear timers and internal state

Events:

  • change - File created/modified (filePath)
  • delete - File deleted (filePath)
  • before - Before processing batch (changes array of [filePath, eventName] tuples)
  • after - After processing batch (changes)

Examples

Basic File Watching

const metawatch = require('metawatch');

const watcher = new metawatch.DirectoryWatcher({ timeout: 500 });

watcher.watch('./src');

watcher.on('change', (fileName) => {
  console.log(`File changed: ${fileName}`);
  // Trigger rebuild, reload, etc.
});

watcher.on('delete', (fileName) => {
  console.log(`File deleted: ${fileName}`);
  // Clean up references, etc.
});

File System Backup Monitor

const metawatch = require('metawatch');
const fs = require('node:fs');

const watcher = new metawatch.DirectoryWatcher({ timeout: 1000 });
const backupQueue = new Set();

watcher.watch('/important/documents');

watcher.on('change', (fileName) => {
  console.log(`File modified: ${fileName}`);
  backupQueue.add(fileName);
});

watcher.on('delete', (fileName) => {
  console.log(`File deleted: ${fileName}`);
  // Remove from backup if it exists
  backupQueue.delete(fileName);
});

watcher.on('after', (changes) => {
  if (backupQueue.size > 0) {
    console.log(`Backing up ${backupQueue.size} files...`);
    // Process backup queue
    backupQueue.clear();
  }
});

Multiple Directory Monitoring

const fs = require('node:fs');
const path = require('node:path');
const metawatch = require('metawatch');

const watcher = new metawatch.DirectoryWatcher({ timeout: 200 });

const directories = ['./src', './tests', './docs', './config'];

directories.forEach((dir) => {
  if (fs.existsSync(dir)) {
    watcher.watch(path.resolve(dir));
    console.log(`Watching: ${dir}`);
  }
});

watcher.on('change', (fileName) => {
  const relativePath = path.relative(process.cwd(), fileName);
  console.log(`Changed: ${relativePath}`);
});

watcher.on('before', (changes) => {
  console.log(`Processing ${changes.length} changes...`);
});

watcher.on('after', (changes) => {
  console.log(`Completed processing ${changes.length} changes`);
});

TypeScript Usage

import { DirectoryWatcher, DirectoryWatcherOptions } from 'metawatch';

const options: DirectoryWatcherOptions = {
  timeout: 500,
};

const watcher = new DirectoryWatcher(options);

watcher.watch('./src');

watcher.on('change', (fileName: string) => {
  console.log(`File changed: ${fileName}`);
});

watcher.on('delete', (fileName: string) => {
  console.log(`File deleted: ${fileName}`);
});

Error Handling

const watcher = new metawatch.DirectoryWatcher();

watcher.on('error', (error) => {
  console.error('Watcher error:', error);
});

try {
  watcher.watch('/restricted/path');
} catch (error) {
  console.error('Failed to watch directory:', error.message);
}

Contributors

See AUTHORS and contributors on GitHub.

License & Contributors

Copyright (c) 2020-2026 Metarhia contributors. Metawatch is MIT licensed. Metawatch is a part of Metarhia technology stack.