{"id":17369,"library":"status-code-enum","title":"HTTP Status Code Enum","description":"status-code-enum is a TypeScript enum that provides a comprehensive collection of standard HTTP status codes. It is currently at version 1.0.0, indicating a stable API suitable for production use. The package utilizes `semantic-release`, suggesting a consistent, automated release cadence driven by commit messages; new versions are published as features or fixes are introduced rather than on a fixed calendar schedule. Its primary differentiation is its direct provision of these codes as a robust TypeScript enum, offering strong type safety and auto-completion benefits within TypeScript projects. This makes it a reliable and convenient alternative to using magic numbers or manually defining constants for HTTP responses. This approach significantly enhances code readability and maintainability by eliminating the need for developers to remember specific numeric codes or to repeatedly define them across various projects. The enum covers informational, success, redirection, client error, and server error codes as defined by HTTP standards.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/typeslick/status-code-enum","tags":["javascript","typescript"],"install":[{"cmd":"npm install status-code-enum","lang":"bash","label":"npm"},{"cmd":"yarn add status-code-enum","lang":"bash","label":"yarn"},{"cmd":"pnpm add status-code-enum","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The `StatusCode` enum is a named export. Do not use a default import.","wrong":"import StatusCode from 'status-code-enum'","symbol":"StatusCode","correct":"import { StatusCode } from 'status-code-enum'"},{"note":"For CommonJS environments, `StatusCode` must be destructured from the `require` call as it's a named export.","wrong":"const StatusCode = require('status-code-enum')","symbol":"StatusCode","correct":"const { StatusCode } = require('status-code-enum')"},{"note":"Individual enum members are accessed via the `StatusCode` namespace, not directly imported.","wrong":"import { ClientErrorBadRequest } from 'status-code-enum'","symbol":"StatusCode.ClientErrorBadRequest","correct":"import { StatusCode } from 'status-code-enum'; /* ... */ res.statusCode = StatusCode.ClientErrorBadRequest;"}],"quickstart":{"code":"import { StatusCode } from 'status-code-enum';\n\n// Example in a hypothetical HTTP response context (e.g., Node.js http module or framework)\ninterface HttpResponse {\n  statusCode: number;\n  send: (message: string) => void;\n}\n\nconst mockResponse: HttpResponse = {\n  statusCode: 200, // Default or initial status\n  send: (message: string) => console.log(`Sending response: ${message} (Status: ${mockResponse.statusCode})`)\n};\n\n// Setting a 400 Bad Request status\nmockResponse.statusCode = StatusCode.ClientErrorBadRequest;\nmockResponse.send(\"Your request was malformed.\");\n\n// Setting a 200 OK status\nmockResponse.statusCode = StatusCode.SuccessOK;\nmockResponse.send(\"Request processed successfully.\");\n\n// Setting a 404 Not Found status\nmockResponse.statusCode = StatusCode.ClientErrorNotFound;\nmockResponse.send(\"The requested resource could not be found.\");\n\n// Accessing the enum member directly\nconst unauthorizedCode: number = StatusCode.ClientErrorUnauthorized;\nconsole.log(`Unauthorized status code is: ${unauthorizedCode}`);\n","lang":"typescript","description":"Demonstrates how to import the `StatusCode` enum and assign its members to a hypothetical HTTP response object's status code, showcasing type-safe access to common HTTP codes."},"warnings":[{"fix":"Refer to official IETF RFCs for a complete list of all possible HTTP status codes, including experimental ones, if `status-code-enum` does not contain a specific code you require.","message":"This library strictly provides standard HTTP status codes. It does not include non-standard, experimental, or deprecated codes unless they are officially adopted. Developers should consult HTTP specifications if looking for highly specialized or provisional codes.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Treat the `StatusCode` enum as an immutable set of predefined values. If custom status codes are needed, define them separately rather than attempting to extend this enum.","message":"Attempting to modify the `StatusCode` enum at runtime will not work as TypeScript enums are typically compiled to objects with read-only properties, or are tree-shaken as type-only constructs if used only for type information.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure you are using `import { StatusCode } from 'status-code-enum';` for ESM/TypeScript or `const { StatusCode } = require('status-code-enum');` for CommonJS.","cause":"The `StatusCode` enum was not correctly imported before use in an ESM or CommonJS module.","error":"ReferenceError: StatusCode is not defined"},{"fix":"Correct the spelling of the enum member. Use IDE auto-completion to ensure the correct member name is used (e.g., `StatusCode.ClientErrorBadRequest`).","cause":"Attempted to access a non-existent or misspelled member of the `StatusCode` enum. TypeScript's strict type checking prevents this.","error":"Property 'ClientErrorBadRequestt' does not exist on type 'typeof StatusCode'. Did you mean 'ClientErrorBadRequest'?"}],"ecosystem":"npm","meta_description":null}