Registry / testing / create-http-error

create-http-error

JSON →
library1.0.3jsnpmunverified

This package (version 1.0.3) provides a simple factory function to create HTTP error objects with a given numeric status code. It was last released in an earlier era and is not actively maintained. The error object includes the code, standard HTTP message, and optional custom message or properties. It exposes `.toString()`, `.toJSON()`, and a `.codes` property. It only supports CommonJS (require) and is intended for Node.js environments. No releases have been made in years, and the package may be considered stable but deprecated in favor of more modern alternatives like 'http-errors' or 'http-errors-promise'. Usage with ESM (import) may fail without a wrapper.

npm install create-http-error
INSTALL
IMPORT
SIG · CREATE-HTTP-ERROR
C
create-http-error
testingjavascriptv1.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HttpError
✓ const HttpError = require('create-http-error')
✗ import HttpError from 'create-http-error'
Package exposes module.exports, not a default ESM export. Use CommonJS require() in Node.
HttpError (ESM)
✓ import HttpError from 'create-http-error'
✗ const { HttpError } = require('create-http-error')
If using ESM, the entire module is exported as a function. A named destructure is incorrect.
HttpError.codes
✓ const codes = require('create-http-error').codes
✗ import { codes } from 'create-http-error'
Accessing .codes via require or default import; named ESM import is not supported.

Shows creating HTTP errors with code, message, properties, and accessing status codes.

const HttpError = require('create-http-error'); // Create an error with status 400 const err400 = HttpError(400); console.log(err400.status); // 400 console.log(err400.message); // 'Bad Request' console.log(err400.toString()); // 'HttpError 400: Bad Request' // With custom message const err404 = HttpError(404, 'Not found'); console.log(err404.message); // 'Not found' // With properties const err500 = HttpError(500, 'Server error', { custom: true }); console.log(err500.custom); // true // Using .codes console.log(HttpError.codes[200]); // 'OK'
Debug
Known issues
deprecatedPackage is unmaintained since 2015. Use 'http-errors' or 'http-errors-promise' instead.
fix
Switch to http-errors: const createError = require('http-errors'); createError(400);
affects: >=0.0.0
gotchaPassing a string to HttpError works (e.g., '400') but is not documented as intended; it coerces to number.
fix
Always pass a number: HttpError(400).
affects: >=0.0.0
gotchaThe package does not support ESM import natively. Attempting import will fail or require .mjs config.
fix
Use CommonJS require() or wrap with createRequire.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: HttpError is not a function
Using named import instead of default import with require.
fix
Use const HttpError = require('create-http-error');
Cannot find module 'create-http-error'
Package not installed or not found in node_modules.
fix
Run npm install create-http-error --save
HttpError is not defined
Using ES modules without proper import or require.
fix
If using ES modules, use import HttpError from 'create-http-error' or switch to CommonJS.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
create-http-error — npm install create-http-error · libregistry