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.
Common errors
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.
Warnings
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).
Install
npm install http-error yarn add http-error pnpm add http-error Imports
- HttpError (namespace) wrong
import HttpError from 'http-error';correctconst HttpError = require('http-error'); const err = new HttpError.NotFound('message'); - NotFound wrong
import { NotFound } from 'http-error';correctconst { NotFound } = require('http-error'); const err = new NotFound('message'); - InternalServerError
const InternalServerError = require('http-error').InternalServerError; const err = new InternalServerError('message');
Quickstart
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