{"id":16077,"library":"http-status-code","title":"HTTP Status Code Utilities","description":"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.","status":"active","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/daanvanham/http-status-code","tags":["javascript","http","status","code"],"install":[{"cmd":"npm install http-status-code","lang":"bash","label":"npm"},{"cmd":"yarn add http-status-code","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-status-code","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"const HTTPStatusCode = require('http-status-code').HTTPStatusCode;","symbol":"HTTPStatusCode","correct":"import HTTPStatusCode from 'http-status-code';"},{"note":"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.","wrong":"import { getMessage } from 'http-status-code';","symbol":"getMessage","correct":"import HTTPStatusCode from 'http-status-code';\nconst message = HTTPStatusCode.getMessage(200);"},{"note":"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.","wrong":"import { HTTP11_CODES } from 'http-status-code';","symbol":"All HTTP/1.1 Status Codes","correct":"import HTTPStatusCode from 'http-status-code';\nconst codes = HTTPStatusCode.getProtocolStatusCodes('HTTP/1.1');"}],"quickstart":{"code":"import HTTPStatusCode from 'http-status-code';\n\n// Get the message for a common status code without specifying a protocol\nconsole.log('HTTP 200 message:', HTTPStatusCode.getMessage(200));\n\n// Get the message for a status code specific to HTTP/1.1\nconsole.log('HTTP/1.1 429 message:', HTTPStatusCode.getMessage(429, 'HTTP/1.1'));\n\n// Get the message for a status code that might differ or be unknown in a specific protocol\nconsole.log('WEBDAV 429 message (example of unknown):', HTTPStatusCode.getMessage(429, 'WEBDAV'));\n\n// Retrieve all status codes for a specific protocol\nconst http2Codes = HTTPStatusCode.getProtocolStatusCodes('HTTP/2');\nconsole.log('\\nHTTP/2 status codes (first 5):', Object.entries(http2Codes).slice(0, 5));\n","lang":"javascript","description":"Demonstrates retrieving HTTP status messages for various codes, including protocol-specific lookups, and fetching a list of all codes for a given protocol."},"warnings":[{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=2.0.0"},{"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');`.","message":"The 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.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Refer to the documentation or source for exact protocol string names. Common valid values are 'HTTP/1.0', 'HTTP/1.1', 'HTTP/2'.","message":"Protocol 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.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure `HTTPStatusCode` is correctly imported: `const HTTPStatusCode = require('http-status-code');` in CommonJS or `import HTTPStatusCode from 'http-status-code';` in ESM.","cause":"Attempting to call `getMessage` on an undefined `HTTPStatusCode` object, likely due to incorrect CommonJS import syntax.","error":"TypeError: Cannot read properties of undefined (reading 'getMessage')"},{"fix":"Access `getMessage` as a method of the default import: `import HTTPStatusCode from 'http-status-code'; HTTPStatusCode.getMessage(200);`","cause":"Incorrectly trying to destructure `getMessage` as a named export from an ESM import, when it's a method of the default export.","error":"TypeError: (0 , http_status_code_1.getMessage) is not a function"}],"ecosystem":"npm"}