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

error-guard

v2.0.1

Published

Error Guard is a lightweight, TypeScript-friendly library for standardized error handling in Node.js/Express applications.

Readme

🛡️ Error Guard

Error Guard is a lightweight, TypeScript-friendly library for standardized error handling in Node.js/Express applications.

🔄 Latest Update (v2.0.1)

ErrorGuard is now 10% faster! See full details in the CHANGELOG.md.

Installation

npm install error-guard

Environment Variables

  • Make sure you have a variable named NODE_ENV in your .env file.
  • When process.env.NODE_ENV !== 'production', all error objects include a full stack trace to help with debugging.
  • In production, the stack field is automatically removed to prevent sensitive information from being exposed in API responses.

It provides:

  • Custom error classes with HTTP status codes and error codes
  • Predefined error helpers (BadRequest, ValidationError, etc.)
  • Async route handler wrapper
  • Express error-handling middleware

Usage

  • Basic Example
import express from "express";
import {
  BadRequest,
  asyncHandler,
  createErrorHandler,
} from "error-guard";

const app = express();
app.use(express.json());

app.get(
  "/test",
  asyncHandler(async (req, res) => {
    // Throw a standardized error
    throw BadRequest("Invalid request data");
  })
);
// Global error handler
app.use(createErrorHandler());

app.listen(3000, () => console.log("Server running on port 3000"));
  • Output (JSON):
{
  "status": "fail",
  "code": "BAD_REQUEST",
  "message": "Invalid request data",
  "stack": "Error: ...",
}

Using Predefined Errors

  • BadRequest(message, details) : Invalid request data
  • ValidationError(message, details) : Schema or input validation failed
  • AuthenticationError(message, details) : Invalid or missing credentials
  • AuthorizationError(message, details) : Not allowed to perform this action
  • ResourceNotFound(message, details) : Resource does not exist
  • ConflictError(message, details) : Conflict with an existing resource
  • RateLimitError(message, details) : Too many requests
  • DependencyError(message, details) : External dependency failed
  • InternalError(message, details) : Generic server error
BadRequest(message?: string, details?: any)
ValidationError(message?: string, details?: any)
AuthenticationError(message?: string, details?: any).

You can also provide optional details for more information:

throw ValidationError("Invalid email format", { field: "email" });

Async Handlers

  • Wrap async route handlers to automatically catch errors:
app.get(
  "/async-test",
  asyncHandler(async (req, res) => {
    const data = await fetchData();
    if (!data) throw ResourceNotFound("Data not found");
    res.json(data);
  })
);

Custom Error Handling Middleware

  • You can provide a logger to capture all errors:
app.use(createErrorHandler({
  logger: (err, req) => {
    console.error(`[${req.method}] ${req.url} -`, err);
  }
}));

API Reference

new ErrorGuard(statusCode?: number, code?: string, message?: string, details?: any)
  • statusCode — HTTP status code (default: 500)
  • code — Error code string (default: "ERROR")
  • message — Error message
  • details — Optional extra information

License

MIT License © l1l-01