{"id":17702,"library":"http-sts","title":"HTTP Status Codes Mapper","description":"http-sts (HTTP Status Codes) is a JavaScript/TypeScript library designed to provide a comprehensive and structured collection of HTTP status codes. It maps each code to an object containing its numeric value, a human-readable name, and a detailed description directly sourced from MDN Web Docs. Currently at version 1.1.4, the package offers a stable and reliable way to access information for a wide range of HTTP responses, from informational (1xx) to server error (5xx) codes. Unlike simpler enumeration libraries, http-sts provides rich, descriptive content for each status code, making it suitable for applications that require more than just the code number or a basic name. Its release cadence is generally stable, with updates primarily reflecting changes or additions to HTTP status codes on MDN. Key differentiators include the depth of information provided and its direct lineage from an authoritative source like MDN, ensuring accuracy and detail.","status":"active","version":"1.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/AndreiLucaci/http-sts","tags":["javascript","http status codes","http","status","codes","MDN","MDN status codes","typescript"],"install":[{"cmd":"npm install http-sts","lang":"bash","label":"npm"},{"cmd":"yarn add http-sts","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-sts","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is the main object containing all status code definitions as named properties (e.g., `CODE_200`). Modern projects should prefer ESM imports.","wrong":"const HTTPStatusCodes = require('http-sts').HTTPStatusCodes;","symbol":"HTTPStatusCodes","correct":"import { HTTPStatusCodes } from 'http-sts';"},{"note":"Use `import type` for importing only the TypeScript type definition, preventing it from being bundled into JavaScript output.","wrong":"import { HTTPStatusCodeType } from 'http-sts';","symbol":"HTTPStatusCodeType","correct":"import type { HTTPStatusCodeType } from 'http-sts';"},{"note":"Individual status code objects can be imported directly if only a few specific codes are needed, improving tree-shaking.","wrong":"import HTTPStatusCodes from 'http-sts'; console.log(HTTPStatusCodes.CODE_200);","symbol":"CODE_200","correct":"import { CODE_200 } from 'http-sts';"}],"quickstart":{"code":"import { HTTPStatusCodes, HTTPStatusCodeType } from 'http-sts';\n\n// Access a specific status code object\nconst okStatus: HTTPStatusCodeType = HTTPStatusCodes.CODE_200;\nconsole.log(`Code: ${okStatus.code}`);\nconsole.log(`Name: ${okStatus.name}`);\nconsole.log(`Description: ${okStatus.description}`);\n\n// Iterate over all available status codes (for documentation or internal mapping)\nconsole.log('\\nAll HTTP Status Codes:');\nfor (const key in HTTPStatusCodes) {\n  const statusCode = HTTPStatusCodes[key as keyof typeof HTTPStatusCodes];\n  console.log(`- ${statusCode.code}: ${statusCode.name}`);\n}\n\n// Example of using a specific code in a response (conceptual, depends on framework)\nfunction sendResponse(res: any, status: HTTPStatusCodeType, message: string) {\n  console.log(`\nSending response with status ${status.code} - ${status.name}: ${message}`);\n  // In a real scenario: res.status(status.code).send(message);\n}\n\nsendResponse({}, HTTPStatusCodes.CODE_404, 'Resource not found.');","lang":"typescript","description":"Demonstrates how to import and access individual HTTP status code objects, including their code, name, and description. It also shows how to iterate through all available codes and conceptual usage in a web server context."},"warnings":[{"fix":"Always access status codes using their `CODE_XXX` property names (e.g., `HTTPStatusCodes.CODE_404`). If you need to map a number to a code, you'll need to create a helper function or map over the `HTTPStatusCodes` object.","message":"Direct numeric access like `HTTPStatusCodes[200]` will not work as expected. Status codes are exposed as named properties, e.g., `HTTPStatusCodes.CODE_200`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use the `code` and `name` properties for programmatic logic. Treat `description` as display-only content. Periodically update the package to get the latest MDN descriptions.","message":"The descriptions provided are direct extracts from MDN Web Docs. While generally stable, they are subject to changes on MDN and are embedded at the time of the package's release. Relying on the *exact* string content for parsing or strict comparisons is not recommended.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure you are using a valid `CODE_XXX` property name from the `HTTPStatusCodes` object. Verify the status code actually exists in the library. If using a numeric value, ensure it's correctly mapped to its `CODE_XXX` string representation.","cause":"Attempting to access a status code that does not exist or using incorrect property access (e.g., `HTTPStatusCodes.CODE_999` or `HTTPStatusCodes[200].name`).","error":"TypeError: Cannot read properties of undefined (reading 'name')"},{"fix":"Switch to ESM `import` statements: `import { HTTPStatusCodes } from 'http-sts';`. Ensure your project is configured for ESM if you intend to use it, or stick to CommonJS `require` if your environment explicitly supports it.","cause":"Attempting to use `require()` syntax in an ESM-only context (e.g., a modern Node.js module with `\"type\": \"module\"` in `package.json` or a browser environment).","error":"ReferenceError: require is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}