http-error

raw JSON →
0.0.6 verified Sat Apr 25 auth: no javascript maintenance

Exposes HTTP error codes as Error constructors for Node.js. This package (v0.0.6, last updated in 2014) provides a simple way to create HTTP error objects with status codes (e.g., NotFound, InternalServerError). It is a lightweight alternative to packages like http-errors or boom, but with a smaller API surface and no dependency on Express. Currently in maintenance mode; no releases since 2014.

error TypeError: HttpError.NotFound is not a constructor
cause Using wrong casing or importing incorrectly.
fix
Ensure you use PascalCase: new require('http-error').NotFound('msg')
error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
cause Package does not support ESM; using require() in an ESM environment.
fix
Use dynamic import or convert your project to CommonJS. Alternatively, use a wrapper module with createRequire.
gotcha The package is CommonJS-only. Using ES module import (import ... from) will fail with ERR_REQUIRE_ESM.
fix Use require() instead of import.
deprecated Package has not been updated since 2014. It uses deprecated patterns like var and does not support TypeScript.
fix Consider migrating to actively maintained alternatives like http-errors or http-assert.
gotcha Constructor names are case-sensitive and some use non-standard casing (e.g., 'notFound' vs 'NotFound'). The README uses 'notFound' but actual names are PascalCase.
fix Always use PascalCase constructors as defined in the README table (e.g., NotFound, InternalServerError).
npm install http-error
yarn add http-error
pnpm add http-error

Creates an HTTP error object with a status code and message. Demonstrates basic usage of the NotFound constructor.

const HttpError = require('http-error');
const err = new HttpError.NotFound('Resource not found');
console.log(err.status); // 404
console.log(err.message); // Resource not found
console.log(err instanceof Error); // true