Skip to content

πŸ›‘οΈ Zero-dependency runtime crash guard for Node.js apps with disciplined exits and clean logs

License

Notifications You must be signed in to change notification settings

AbhishekSuresh2/zero-crash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

πŸ’₯ zero-crash

πŸ›‘οΈ Prevent silent crashes in Node.js apps in one line.

πŸ“Š Project Stats

npm downloads stars issues license views

Global runtime crash protection for modern Node.js apps. Stop silent crashes, messy stack traces, and undefined exits.

zero-crash enforces disciplined failures, clean shutdowns, and human-readable crash logs β€” automatically.

Built for 2026 projects, production-safe, and dependency-free.


πŸš€ Why zero-crash?

Most Node apps crash in ugly ways:

  • Silent exits
  • Infinite restart loops
  • Unhandled promise rejections
  • Random process.exit(1)
  • No context, no discipline

zero-crash gives your app a runtime safety contract.

βœ” Zero dependencies βœ” Global crash interception βœ” Clean exit codes βœ” Shutdown hooks βœ” Context-aware crash logs βœ” Works for APIs, CLIs, bots, servers


πŸ“¦ Installation

npm install zero-crash

🧠 Basic Usage

const zero = require("zero-crash");

zero.protect(async () => {
  // your app logic
  startServer();
});

That’s it. Global crash protection is now active.


πŸ”₯ Advanced Usage (Recommended)

🧩 Role Awareness

zero.role("api");

Crash output will include role:

πŸ’₯ [api] RUNTIME_ERROR

πŸ” Environment Validation

zero.requireEnv(["PORT", "DB_URL"]);

zero.protect(async () => {
  startServer();
});

If missing:

πŸ’₯ [app] CONFIG_ERROR
Missing env: DB_URL
Exit: 2

πŸ›‘ Safe Shutdown Hooks

zero.onShutdown(async () => {
  await db.close();
  await redis.quit();
});

Runs on:

  • crash
  • Ctrl+C
  • SIGTERM
  • process exit

⚠️ Crash Classification

throw zero.config("Invalid configuration");
throw zero.dependency("MongoDB not reachable");

Mapped exit codes:

Type Exit Code
Success 0
Runtime Error 1
Config Error 2
Dependency Error 3
Manual Interrupt 130

πŸ§ͺ Full Example

const zero = require("zero-crash");

zero.role("bot");
zero.requireEnv(["SESSION"]);

zero.onShutdown(async () => {
  console.log("Cleaning up...");
});

zero.protect(async () => {
  throw zero.config("SESSION missing");
});

πŸͺ„ Crash Output Example

πŸ’₯ [bot] CONFIG_ERROR
Reason: SESSION missing
Exit: 2
CrashID: ZC-A91F2B
Node: v20.11.1
Memory: 42MB
Uptime: 12s

βš™οΈ Options

zero.protect(app, {
  verbose: false,
  quiet: false,
  json: false,
  onCrash: (err, meta) => {
    // send to webhook / logs
  }
});
Option Description
verbose Show full stack trace
quiet Disable console logs
json Output crash info as JSON
onCrash Custom crash hook

πŸ› οΈ Use Cases

  • REST APIs
  • CLI tools
  • WhatsApp / Telegram bots
  • Cron jobs
  • Microservices
  • Workers & daemons

If it runs on Node.js, zero-crash belongs there.


⭐ Support the Project

If this package improved your app’s stability:

πŸ‘‰ Give it a ⭐ on GitHub Stars help this project reach more developers ❀️


πŸ”„ Updates & Contributions

Want to improve zero-crash?

  • 🐞 Found a bug? β†’ Open an Issue
  • ✨ Feature idea? β†’ Create an Issue
  • πŸ”§ Fix something? β†’ Fork & Pull Request
  • πŸ“ˆ Improvements welcome

Please contribute only through the official repository.


πŸ“œ License

MIT License Β© 2026 Abhishek Suresh https://github.com/AbhishekSuresh2

⚠️ Please do not copy, rebrand, or republish this package as your own without explicit permission.


🌍 Vision for 2026

Failures are inevitable. Chaos is optional.

zero-crash makes crashes predictable, readable, and safe β€” so your app never dies silently again πŸ’₯πŸ›‘οΈ