Registry / http-networking / builtin-status-codes

builtin-status-codes

JSON →
library3.0.0jsnpmunverified

This package, `builtin-status-codes`, provides a direct mapping of HTTP status codes to their corresponding human-readable messages. It retrieves the latest standard codes directly from Node.js's built-in `http` module when running in a Node.js environment, ensuring accuracy and up-to-date information without external dependencies. For browser environments, it offers a pre-built, zero-dependency version, making it suitable for universal JavaScript applications. The current stable version is 3.0.0. Due to its direct sourcing from Node's core and the stable nature of HTTP status codes, its release cadence is typically infrequent, primarily updating when Node.js introduces new codes or when there are build tool chain updates. Its key differentiator is providing a consistent, minimal API for both Node.js and browser contexts, leveraging built-in capabilities where possible.

npm install builtin-status-codes
INSTALL
IMPORT
SIG · BUILTIN-STATUS-COD
B
builtin-status-codes
http-networkingjavascriptv3.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.

codes
import codes from 'builtin-status-codes'
import { codes } from 'builtin-status-codes'
The package exports the status code map as its default export. Named imports like `{ codes }` will not work.
codes
const codes = require('builtin-status-codes')
This is the CommonJS import pattern, suitable for Node.js environments without ES Modules enabled.
codes
type HttpStatusCodeMap = Record<number, string>; import codes from 'builtin-status-codes'
TypeScript users can import the module as a default export; its type is implicitly `Record<number, string>`.

Demonstrates importing the status codes map, retrieving messages for specific numeric codes, and iterating through all available codes.

import codes from 'builtin-status-codes'; // Get the message for a specific status code const okMessage = codes[200]; console.log(`200: ${okMessage}`); // Output: 200: OK const notFoundMessage = codes[404]; console.log(`404: ${notFoundMessage}`); // Output: 404: Not Found const serverErrorMessage = codes[500]; console.log(`500: ${serverErrorMessage}`); // Output: 500: Internal Server Error // Iterate over all known status codes and messages console.log('\nAll available status codes:'); for (const codeStr in codes) { const code = Number(codeStr); // Filter out any non-numeric or inherited properties if (Number.isInteger(code) && code > 0) { console.log(`${code}: ${codes[code]}`); } }
Debug
Known issues
breakingVersion 3.0.0 is a major release. While specific breaking changes are not detailed in the provided README, major version bumps typically introduce API changes, updated environment requirements, or different default behaviors. Users upgrading from 2.x.x should consult the package's changelog.
fix
Review the package's GitHub repository or `CHANGELOG.md` for detailed migration instructions specific to the 3.0.0 release.
affects: >=3.0.0
gotchaThe package provides a mapping from numeric HTTP status *codes* (e.g., `200`) to their descriptive *strings* (e.g., 'OK'). It does not offer a direct reverse lookup (string to number) without manually iterating through the map.
fix
If a reverse lookup is needed, iterate `Object.entries(codes)` and build your own reverse map or search dynamically.
affects: >=1.0.0
gotchaThe browser bundle of `builtin-status-codes` (generated via `npm run build`) is a static snapshot. It might not reflect the absolute latest HTTP status codes as rapidly as the Node.js version, which dynamically queries Node's built-in `http` module at runtime.
fix
For the most current status codes in a browser environment, ensure your `builtin-status-codes` package is updated to the latest version and that your build process includes the most recent browser bundle.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use CommonJS `require()` syntax in an ES Module context (e.g., in a file with `"type": "module"` in `package.json` or a `.mjs` file).
fix
Use `import codes from 'builtin-status-codes'` for ES Modules.
TypeError: codes is not a function
The `codes` export from `builtin-status-codes` is a plain object (a map of numbers to strings), not a callable function.
fix
Access status messages using bracket notation with the numeric code, e.g., `codes[200]`.
TypeError: Cannot read properties of undefined (reading '100')
This typically indicates that the `builtin-status-codes` module failed to load correctly, resulting in `codes` being `undefined`, or you're trying to access a non-existent status code in a context where `codes` might be null/undefined.
fix
Ensure `builtin-status-codes` is correctly installed (`npm install builtin-status-codes`) and imported. Verify that the status code you are trying to access is a valid HTTP status code.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
26
OpenAI (training)
1
Resources
builtin-status-codes — npm install builtin-status-codes · libregistry