Registry / http-networking / node-http-error

node-http-error

JSON →
library2.0.0jsnpmunverified

node-http-error provides a simple mechanism for creating and throwing HTTP-specific errors within Node.js applications, particularly useful for API development with frameworks like Express. This package allows developers to instantiate errors with a given HTTP status code, an optional custom message, and additional properties, while also automatically generating default messages for standard status codes. Key features of version 2.0.0, released in 2014, include full stack traces, the ability to omit the `new` operator when creating instances, and direct access to `status` and `statusCode` properties for integration with error handling middleware. However, this specific package by carsondarling is considered abandoned, with its last update occurring nine years ago. Developers are strongly encouraged to use more actively maintained alternatives like `http-errors` (from `jshttp`) for modern Node.js projects.

npm install node-http-error
INSTALL
IMPORT
SIG · NODE-HTTP-ERROR
N
node-http-error
http-networkingjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

HTTPError
const HTTPError = require('node-http-error');
import { HTTPError } from 'node-http-error';
This package (v2.0.0) is CommonJS only and does not provide ES Module exports. Attempting an ESM import will result in a runtime error.
HTTPError (function call)
next(HTTPError(500, 'Error by design.'));
next(new HTTPError(500, 'Error by design.'));
While `new HTTPError()` works, the library explicitly supports calling `HTTPError()` as a function without `new` for convenience and brevity, as shown in the original documentation.

This quickstart demonstrates how to create and throw `HTTPError` instances within an Express.js application, and how to set up a basic error handling middleware to catch and respond to these errors using their status code and message.

const HTTPError = require('node-http-error'); const express = require('express'); const app = express(); app.get('/error', function(req, res, next) { // Example of throwing a 500 Internal Server Error with a custom message return next(new HTTPError(500, 'Error by design.')); }); app.get('/not-found', function(req, res, next) { // Example of throwing a 404 Not Found error using only the status code return next(HTTPError(404)); }); // Error handler middleware app.use(function(err, req, res, next) { if (err instanceof HTTPError) { res.status(err.status || err.statusCode || 500); res.send(err.message || 'An unexpected error occurred.'); } else { res.status(500).send('Unhandled server error.'); } }); app.listen(3000, () => { console.log('Server listening on http://localhost:3000'); console.log('Try visiting http://localhost:3000/error'); console.log('Try visiting http://localhost:3000/not-found'); });
Debug
Known issues
breakingThe `node-http-error` package (by carsondarling) has been abandoned since 2014. It receives no updates, bug fixes, or security patches, making it unsuitable for new projects or production environments.
fix
Migrate to a currently maintained alternative like `http-errors` (from `jshttp`) or `@curveball/http-errors`, which offer similar functionality with active development and modern JavaScript support.
affects: >=2.0.0
breakingThis package is CommonJS-only. It cannot be directly imported into ES Module (ESM) contexts using `import` statements, leading to `ReferenceError: require is not defined`.
fix
For ESM projects, use an actively maintained package that provides ESM compatibility. If you must use this package in an ESM context, consider dynamic `import()` or transpilation, but migration is strongly recommended.
affects: >=2.0.0
gotchaThe package's reliance on older Node.js HTTP module behavior might be incompatible with stricter HTTP parser changes introduced in Node.js v12 and later, potentially leading to unexpected error handling or server behavior.
fix
Upgrade to a modern HTTP error utility that is actively tested and maintained with current Node.js versions.
affects: >=2.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` in an ES Module (ESM) context without a CommonJS compatibility layer.
fix
This package is CommonJS-only. Either refactor your project to use CommonJS, use dynamic `import()` (if compatible with your setup), or, preferably, migrate to a modern, actively maintained HTTP error library that supports ESM.
TypeError: app.use() requires a middleware function but got a undefined
The `HTTPError` object (or the `node-http-error` module itself) failed to load or was incorrectly referenced, resulting in `undefined` being passed where a function was expected.
fix
Ensure `require('node-http-error')` correctly resolves and that `HTTPError` is accessible in your scope. Verify file paths and npm installation. Given the package's age, ensure your Node.js environment is not causing compatibility issues during module loading.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
node-http-error — npm install node-http-error · libregistry