{"id":15974,"library":"builtin-status-codes","title":"HTTP Status Codes Map","description":"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.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/bendrucker/builtin-status-codes","tags":["javascript","http","status","codes","builtin","map"],"install":[{"cmd":"npm install builtin-status-codes","lang":"bash","label":"npm"},{"cmd":"yarn add builtin-status-codes","lang":"bash","label":"yarn"},{"cmd":"pnpm add builtin-status-codes","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports the status code map as its default export. Named imports like `{ codes }` will not work.","wrong":"import { codes } from 'builtin-status-codes'","symbol":"codes","correct":"import codes from 'builtin-status-codes'"},{"note":"This is the CommonJS import pattern, suitable for Node.js environments without ES Modules enabled.","symbol":"codes","correct":"const codes = require('builtin-status-codes')"},{"note":"TypeScript users can import the module as a default export; its type is implicitly `Record<number, string>`.","symbol":"codes","correct":"type HttpStatusCodeMap = Record<number, string>;\nimport codes from 'builtin-status-codes'"}],"quickstart":{"code":"import codes from 'builtin-status-codes';\n\n// Get the message for a specific status code\nconst okMessage = codes[200];\nconsole.log(`200: ${okMessage}`); // Output: 200: OK\n\nconst notFoundMessage = codes[404];\nconsole.log(`404: ${notFoundMessage}`); // Output: 404: Not Found\n\nconst serverErrorMessage = codes[500];\nconsole.log(`500: ${serverErrorMessage}`); // Output: 500: Internal Server Error\n\n// Iterate over all known status codes and messages\nconsole.log('\\nAll available status codes:');\nfor (const codeStr in codes) {\n  const code = Number(codeStr);\n  // Filter out any non-numeric or inherited properties\n  if (Number.isInteger(code) && code > 0) {\n    console.log(`${code}: ${codes[code]}`);\n  }\n}\n","lang":"typescript","description":"Demonstrates importing the status codes map, retrieving messages for specific numeric codes, and iterating through all available codes."},"warnings":[{"fix":"Review the package's GitHub repository or `CHANGELOG.md` for detailed migration instructions specific to the 3.0.0 release.","message":"Version 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.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"If a reverse lookup is needed, iterate `Object.entries(codes)` and build your own reverse map or search dynamically.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Use `import codes from 'builtin-status-codes'` for ES Modules.","cause":"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).","error":"ReferenceError: require is not defined"},{"fix":"Access status messages using bracket notation with the numeric code, e.g., `codes[200]`.","cause":"The `codes` export from `builtin-status-codes` is a plain object (a map of numbers to strings), not a callable function.","error":"TypeError: codes is not a function"},{"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.","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading '100')"}],"ecosystem":"npm"}