Registry / http-networking / http-codes

http-codes

JSON →
library1.0.0jsnpmunverified

This `http-codes` package provides a straightforward JavaScript object that maps common HTTP status message constants (e.g., `OK`, `NOT_FOUND`) to their corresponding numeric codes (e.g., `200`, `404`). Originally released as version `1.0.0` in 2014, it explicitly based its mapping on the built-in HTTP status codes available in Node.js `0.10.22`. The package emphasizes simplicity and a lack of external dependencies, aiming to automatically incorporate updates from Node.js's internal HTTP module, although it has not received any updates since its initial release. Due to its age and lack of maintenance, it does not include many modern HTTP status codes and is primarily suitable for legacy Node.js environments or projects that specifically require the exact mapping from Node.js `0.10.22`.

npm install http-codes
INSTALL
IMPORT
SIG · HTTP-CODES
H
http-codes
http-networkingjavascriptv1.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.

httpCodes
const httpCodes = require('http-codes');
import httpCodes from 'http-codes';
This package is a CommonJS module and directly exports the status code map object. Modern ESM imports will fail without a CJS interoperability layer.
OK
const { OK, NOT_FOUND } = require('http-codes');
import { OK } from 'http-codes';
While the map contains properties like `OK`, direct destructuring requires CommonJS `require()`. Named ESM imports are not supported.

Demonstrates how to `require` the `http-codes` map and access specific status codes. It also shows a basic Node.js HTTP server using these codes to set response statuses.

const httpCodes = require('http-codes'); console.log('HTTP Status Codes Map:'); console.log(httpCodes); // Access a specific status code const okCode = httpCodes.OK; console.log(`\nOK (200): ${okCode}`); const notFoundCode = httpCodes.NOT_FOUND; console.log(`NOT_FOUND (404): ${notFoundCode}`); const imATeapotCode = httpCodes.IM_A_TEAPOT; console.log(`IM_A_TEAPOT (418): ${imATeapotCode}`); // Example usage in a simple server (requires Node.js http module) const http = require('http'); const server = http.createServer((req, res) => { if (req.url === '/success') { res.writeHead(httpCodes.OK, { 'Content-Type': 'text/plain' }); res.end('Request successful!'); } else if (req.url === '/not-found') { res.writeHead(httpCodes.NOT_FOUND, { 'Content-Type': 'text/plain' }); res.end('Resource not found.'); } else { res.writeHead(httpCodes.IM_A_TEAPOT, { 'Content-Type': 'text/plain' }); res.end('I\u0027m a teapot.'); } }); server.listen(3000, () => { console.log('\nServer listening on http://localhost:3000'); console.log('Try visiting /success, /not-found, or any other path.'); });
Debug
Known issues
breakingThis package is extremely old, published in 2014, and specifically based on Node.js 0.10.22. It is not compatible with modern JavaScript module systems (ESM) without explicit CommonJS interop.
fix
For modern applications, consider using actively maintained alternatives like `http-status-codes` or `http-status`. If forced to use, ensure your environment supports CommonJS `require()` and consider a bundler to handle compatibility.
affects: 1.0.0
gotchaThe package does not contain newer HTTP status codes defined after 2014 (e.g., 421 Misdirected Request, 425 Too Early, 451 Unavailable For Legal Reasons, 103 Early Hints). Relying on this package for a comprehensive list of modern codes will lead to omissions.
fix
Always verify if a specific HTTP code is present. For up-to-date and complete HTTP status code lists, use current libraries like `http-status-codes` which are actively maintained and incorporate RFC updates.
affects: 1.0.0
gotchaThe package exports a plain object directly. There are no functions to get status messages from codes, or to parse messages, which are common features in more modern HTTP status code libraries.
fix
If message retrieval or reverse lookups are needed, you will need to implement that logic yourself or switch to a more feature-rich library.
affects: 1.0.0
Errors
Common errors & fixes
SyntaxError: Named export 'OK' not found. The requested module 'http-codes' does not provide an export named 'OK'
Attempting to use ES module named import syntax (`import { OK } from 'http-codes';`) with a CommonJS-only package.
fix
Use CommonJS `require()` syntax: `const { OK } = require('http-codes');` or `const httpCodes = require('http-codes'); const okCode = httpCodes.OK;`
Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported.
Attempting to `require()` a package in an ESM context that does not provide a CommonJS entry point or is explicitly ESM-only. (This package is CJS, but this error is common for developers trying to 'require' in ESM projects)
fix
While `http-codes` *is* CJS, this error often appears when attempting to use CJS-only packages in an ESM project without proper configuration. For `http-codes`, ensure your project context is CJS, or if ESM, use dynamic `import()`: `const httpCodes = await import('http-codes');` (though direct object access might need `httpCodes.default` depending on interop). Better yet, use a modern alternative.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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