Registry / devops / http-statuses

http-statuses

JSON →
library0.2.0jsnpmunverified

Node.js wrapper for HTTP status codes and error creation. Current stable version 0.2.0. Provides an object-oriented interface to access HTTP status codes by name (e.g., BAD_REQUEST, OK), each containing `code`, `message`, and a `createError()` method to generate Node.js Error instances that include the full status data. Lightweight alternative to packages like `http-status` or `http-status-codes`, with built-in error construction support.

npm install http-statuses
INSTALL
IMPORT
SIG · HTTP-STATUSES
H
http-statuses
devopsjavascriptv0.2.0
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.

HTTP_STATUSES
const HTTP_STATUSES = require('http-statuses');
import HTTP_STATUSES from 'http-statuses';
Package uses CommonJS and does not provide ESM exports. Use require().
HTTP_STATUSES.BAD_REQUEST
HTTP_STATUSES.BAD_REQUEST
HTTP_STATUSES['400']
Access statuses by name (e.g., BAD_REQUEST), not by numeric code.
createError
HTTP_STATUSES.BAD_REQUEST.createError('message')
new HTTP_STATUSES.BAD_REQUEST.Error('message')
createError() is a method on the status object, not a constructor.

Shows how to require the package, access status codes by name, and use createError() in an Express route.

const HTTP_STATUSES = require('http-statuses'); const express = require('express'); const app = express(); app.get('/', (req, res) => { if (!req.query.ok) { res.status(HTTP_STATUSES.BAD_REQUEST.code) .send(HTTP_STATUSES.BAD_REQUEST.createError('Not ok').message); } else { res.sendStatus(HTTP_STATUSES.OK.code); } }); app.listen(3000, () => console.log('Server on 3000'));
Debug
Known issues
gotchaPackage does not support ESM imports.
fix
Use require() or dynamic import().
gotchaStatus objects are not enumerable by numeric code; only by name.
fix
Access via HTTP_STATUSES.BAD_REQUEST, not HTTP_STATUSES['400'].
gotchacreateError() returns a plain Error instance, not a custom class. Instanceof checks will fail for custom error classes.
fix
Use error.message or error.httpStatus.code; do not rely on instanceof.
Errors
Common errors & fixes
Error: Cannot find module 'http-statuses'
Package not installed.
fix
Run npm install http-statuses
TypeError: HTTP_STATUSES.BAD_REQUEST.createError is not a function
Accessing the module incorrectly (e.g., using default import in ESM).
fix
Use const HTTP_STATUSES = require('http-statuses');
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
http-statuses — npm install http-statuses · libregistry