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

@anhkhoakz/express-http-errors

v1.0.0

Published

Express-friendly HTTP errors with typed status factories.

Readme

@anhkhoakz/http-errors

Express-friendly HTTP errors with typed status factories.

The package exports a single HttpError class with:

  • err.status and err.statusCode for Express middleware
  • generated helpers like HttpError.notFound() and HttpError[404]()
  • a HttpError.success() alias for 200 OK
  • optional details, headers, cause, and expose metadata
  • zero runtime dependencies

Install

npm install @anhkhoakz/http-errors

Quick Start

import express from "express";
import { HttpError } from "@anhkhoakz/http-errors";

const app = express();

app.get("/users/:id", async (req, res) => {
  if (req.params.id === "0") {
    throw HttpError.notFound("User not found", {
      details: { userId: req.params.id },
    });
  }

  res.json({ id: req.params.id });
});

app.use((err, req, res, next) => {
  if (!HttpError.is(err)) {
    return next(err);
  }

  if (err.headers) {
    res.set(err.headers);
  }

  res.status(err.status).json({
    error: err.message,
    details: err.expose ? err.details : undefined,
  });
});

Express 5 treats rejected async handlers as errors automatically. Error middleware must still be registered last and use the four-argument signature (err, req, res, next).

API

HttpError

import { HttpError } from "@anhkhoakz/http-errors";

throw HttpError.badRequest("Invalid payload");
throw HttpError[401]("Missing token");
throw HttpError.success();

Each instance includes:

type HttpErrorInstance = {
  message: string;
  status: number;
  statusCode: number;
  statusText: string;
  expose: boolean;
  headers?: Readonly<Record<string, string | readonly string[]>>;
  details?: unknown;
  cause?: unknown;
};

HttpError.from(status, ...)

Create an error when the status is only known at runtime.

const status = 429 as const;
const error = HttpError.from(status, "Rate limit exceeded");

HttpError.is(value)

Runtime guard for custom middleware.

if (HttpError.is(err)) {
  console.log(err.status, err.message);
}

HttpError.isStatusCode(value)

Check whether a number is a generated status code.

if (HttpError.isStatusCode(input)) {
  throw HttpError.from(input);
}

HttpError.getStatus(code)

Read generated metadata for a status code.

const status = HttpError.getStatus(404);

status.name;
status.constant;
status.comment.description;
status.comment.doc;

Types

import type {
  HttpErrorHeaders,
  HttpErrorOptions,
  HttpErrorStatusCode,
  HttpErrorStatusConstant,
  HttpErrorStatusName,
} from "@anhkhoakz/http-errors";

Development

bun install
bun run generate
bun run typecheck
bun test
bun run build