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

@misaka-net/fatal-guard

v0.2.2

Published

Zero-dependency non-invasive fatal error guard — capture uncaught exceptions and unhandled rejections, route structured 4-field payload to external handler via process.env.FATAL_HANDLER

Readme

@misaka-net/fatal-guard

Zero-dependency non-invasive fatal error guard for Node.js CLIs.
Capture uncaught exceptions, unhandled rejections, and non-zero exits — route a structured 4-field payload to any external handler.

npm i @misaka-net/fatal-guard
FATAL_HANDLER=/usr/bin/logger node -r @misaka-net/fatal-guard/register ./app.js

One env var. No source code changes.


Quick start

Wrapper mode (no code changes needed)

# Wrap any Node.js CLI — automatically detects crashes via stderr + exit code
FATAL_HANDLER=/usr/bin/logger npx @misaka-net/fatal-guard -- node app.js

# Works with any CLI tool — Vite, E2B, OpenClaw, tsdown, etc.
FATAL_HANDLER=/usr/bin/logger npx @misaka-net/fatal-guard -- ./node_modules/.bin/vite build

Preload mode (node -r)

npm i @misaka-net/fatal-guard
FATAL_HANDLER=/usr/bin/logger node -r @misaka-net/fatal-guard/register ./app.js

Both modes produce identical 4-field payloads in syslog on crash.

# 1. Install
npm i @misaka-net/fatal-guard

# 2. Run any Node.js CLI with the guard preloaded
FATAL_HANDLER=/usr/bin/logger node -r @misaka-net/fatal-guard/register ./your-cli.js

# 3. Trigger a fatal error — watch syslog light up
#    (uncaught exceptions, unhandled rejections, non-zero exits all captured)

Real syslog output after an uncaught exception:

Jun 19 08:38:26 hostname logger[180739]:
  {"schemaVersion":1,"reason":"uncaught_exception",
   "timestamp":"2026-06-19T08:38:26.091Z","pid":180739}

Jun 19 08:38:26 hostname logger[180739]:
  {"schemaVersion":1,"reason":"exit_code",
   "timestamp":"2026-06-19T08:38:26.096Z","pid":180739}

How it works

register.js hooks into three process-level fatal signals:

| Signal | Trigger | Behavior | |--------|---------|----------| | uncaughtException | Synchronous throw not caught by any try/catch | Fires handler, prints to stderr, exits with code 1 | | unhandledRejection | Async promise rejection with no .catch() | Fires handler, prints warning | | exit_code / SIGTERM / SIGINT | Non-zero exit or termination signal | Fires handler |

On each signal, the handler executable is spawned with a single JSON argv argument:

{
  "schemaVersion": 1,
  "reason": "uncaught_exception",
  "timestamp": "2026-06-19T04:20:00.000Z",
  "pid": 12345
}

4 fields only. No stack traces, no environment variables, no secrets. Designed to be redacted by default — the handler decides what to enrich.


Handler examples

| Handler | Command | Effect | |---------|---------|--------| | syslog | FATAL_HANDLER=/usr/bin/logger | Writes to systemd journal / syslog | | HTTP webhook | FATAL_HANDLER=/usr/bin/curl | Receives JSON as argv[1] — pair with a small wrapper script for HTTP POST | | Custom script | FATAL_HANDLER=/opt/alert-to-slack.sh | Write your own alert pipeline |


Design principles

| Principle | Implementation | |-----------|---------------| | Zero dependencies | require('node:child_process') only | | Non-blocking | spawn + detached: true + unref() — handler never blocks shutdown | | Injection-safe | shell: false — no shell interpretation of env var or payload | | Fire-and-forget | Handler failure is silently swallowed — process continues | | Redacted by default | 4 fields only — no stack, no env vars, no secrets |


API

const { buildPayload, runHandler } = require('@misaka-net/fatal-guard');

buildPayload('uncaught_exception');
// → '{"schemaVersion":1,"reason":"uncaught_exception","timestamp":"...","pid":12345}'

runHandler('uncaught_exception');
// → spawns FATAL_HANDLER with payload as argv[1], or no-op if FATAL_HANDLER is unset

Related

  • GitHub
  • npm: @misaka-net/fatal-guard