Registry / http-networking / http-status-code

http-status-code

JSON →
library0.0.11jsnpmunverified

The `http-status-code` package provides a straightforward, protocol-aware utility for retrieving human-readable messages associated with HTTP status codes. Currently at version 2.1.0, this library does not indicate a rapid release cadence, suggesting a stable, mature, and low-maintenance tool. Its primary differentiation lies in allowing developers to specify the HTTP protocol version (e.g., HTTP/1.0, HTTP/1.1, HTTP/2) when querying for a status message, ensuring accuracy for protocol-specific codes or messages. If no protocol is specified, it defaults to a comprehensive set. It's a simple, focused solution for translating numeric status codes into their standard descriptions.

npm install http-status-code
INSTALL
IMPORT
SIG · HTTP-STATUS-CODE
H
http-status-code
http-networkingjavascriptv0.0.11
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.

HTTPStatusCode
import HTTPStatusCode from 'http-status-code';
const HTTPStatusCode = require('http-status-code').HTTPStatusCode;
While the README shows CommonJS `require`, modern Node.js and bundlers often resolve `default` export for CommonJS modules. The package may not explicitly ship ESM, but this import pattern generally works. For pure CJS, `const HTTPStatusCode = require('http-status-code');` is correct.
getMessage
import HTTPStatusCode from 'http-status-code'; const message = HTTPStatusCode.getMessage(200);
import { getMessage } from 'http-status-code';
The `getMessage` function is a method of the default exported object, not a named export. Attempting to destructure it directly will result in an undefined function.
All HTTP/1.1 Status Codes
import HTTPStatusCode from 'http-status-code'; const codes = HTTPStatusCode.getProtocolStatusCodes('HTTP/1.1');
import { HTTP11_CODES } from 'http-status-code';
The library exposes an API to retrieve codes based on protocol, rather than exporting individual protocol code objects. Access through the `getProtocolStatusCodes` method is the intended pattern.

Demonstrates retrieving HTTP status messages for various codes, including protocol-specific lookups, and fetching a list of all codes for a given protocol.

import HTTPStatusCode from 'http-status-code'; // Get the message for a common status code without specifying a protocol console.log('HTTP 200 message:', HTTPStatusCode.getMessage(200)); // Get the message for a status code specific to HTTP/1.1 console.log('HTTP/1.1 429 message:', HTTPStatusCode.getMessage(429, 'HTTP/1.1')); // Get the message for a status code that might differ or be unknown in a specific protocol console.log('WEBDAV 429 message (example of unknown):', HTTPStatusCode.getMessage(429, 'WEBDAV')); // Retrieve all status codes for a specific protocol const http2Codes = HTTPStatusCode.getProtocolStatusCodes('HTTP/2'); console.log('\nHTTP/2 status codes (first 5):', Object.entries(http2Codes).slice(0, 5));
Debug
Known issues
gotchaThe `getMessage` function returns 'Unknown' if the status code or protocol combination is not found. There is no explicit error thrown, which might mask issues if expecting specific messages.
fix
Always check the return value of `getMessage` to ensure it's not 'Unknown' if you need to rely on a specific message being present. Consider falling back to a generic message or logging a warning if 'Unknown' is returned.
affects: >=2.0.0
gotchaThe package primarily uses CommonJS `require` syntax in its examples. While modern tools can often consume it with ESM `import`, ensure your build pipeline correctly handles CommonJS module interoperability if you encounter import issues in an ESM-only environment.
fix
If using TypeScript or a modern bundler, `import HTTPStatusCode from 'http-status-code';` should work. For strict CommonJS environments, use `const HTTPStatusCode = require('http-status-code');`.
affects: >=2.0.0
gotchaProtocol names are case-sensitive and must match the internal definitions (e.g., 'HTTP/1.1', 'HTTP/2'). Providing an incorrectly cased or non-existent protocol name will result in an 'Unknown' message or an empty list of status codes.
fix
Refer to the documentation or source for exact protocol string names. Common valid values are 'HTTP/1.0', 'HTTP/1.1', 'HTTP/2'.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'getMessage')
Attempting to call `getMessage` on an undefined `HTTPStatusCode` object, likely due to incorrect CommonJS import syntax.
fix
Ensure `HTTPStatusCode` is correctly imported: `const HTTPStatusCode = require('http-status-code');` in CommonJS or `import HTTPStatusCode from 'http-status-code';` in ESM.
TypeError: (0 , http_status_code_1.getMessage) is not a function
Incorrectly trying to destructure `getMessage` as a named export from an ESM import, when it's a method of the default export.
fix
Access `getMessage` as a method of the default import: `import HTTPStatusCode from 'http-status-code'; HTTPStatusCode.getMessage(200);`
Upgrade
Version history
0.0.11latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
http-status-code — npm install http-status-code · libregistry