{"id":17267,"library":"http-status-enum","title":"HTTP Status Enum","description":"http-status-enum is a lightweight JavaScript/TypeScript library designed to provide a comprehensive, read-only enumeration of standard HTTP status codes. It offers a convenient dual-access mechanism, allowing developers to retrieve status descriptions from numeric codes (e.g., `500` yields `INTERNAL_SERVER_ERROR`) and vice-versa. The package is currently stable at version 1.0.2, with a slow, maintenance-focused release cadence primarily addressing module resolution and type definition correctness. Its key differentiators include its minimal footprint, explicit TypeScript type definitions for enhanced developer experience and type safety, and its straightforward API for consistent access to HTTP status information without external dependencies or complex configurations, making it a reliable choice for various application contexts.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/KyleNeedham/http-status-enum","tags":["javascript","http","status","codes","typescript"],"install":[{"cmd":"npm install http-status-enum","lang":"bash","label":"npm"},{"cmd":"yarn add http-status-enum","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-status-enum","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library exports a default enum object. Named imports will result in undefined.","wrong":"import { HTTP_STATUS_CODES } from 'http-status-enum';","symbol":"HTTP_STATUS_CODES","correct":"import HTTP_STATUS_CODES from 'http-status-enum';"},{"note":"When consuming an ESM default export from CommonJS, the `.default` property must be accessed. This was resolved for CJS with v1.0.1.","wrong":"const HTTP_STATUS_CODES = require('http-status-enum');","symbol":"HTTP_STATUS_CODES (CommonJS)","correct":"const HTTP_STATUS_CODES = require('http-status-enum').default;"},{"note":"To explicitly type variables that store the enum or subsets, use `typeof HTTP_STATUS_CODES` as the type for the imported enum object.","symbol":"TypeOfHttpStatusCodes","correct":"type HttpStatusCodeMap = typeof HTTP_STATUS_CODES;"}],"quickstart":{"code":"import HTTP_STATUS_CODES from 'http-status-enum';\n\n// Accessing status description by numeric code\nconst internalServerErrorDesc = HTTP_STATUS_CODES['500'];\nconsole.log(`Description for 500: ${internalServerErrorDesc}`); // Expected: INTERNAL_SERVER_ERROR\n\nconst notFoundDesc = HTTP_STATUS_CODES['404'];\nconsole.log(`Description for 404: ${notFoundDesc}`); // Expected: NOT_FOUND\n\n// Accessing numeric code by string description\nconst okCode = HTTP_STATUS_CODES.OK;\nconsole.log(`Code for OK: ${okCode}`); // Expected: 200\n\nconst badRequestCode = HTTP_STATUS_CODES.BAD_REQUEST;\nconsole.log(`Code for BAD_REQUEST: ${badRequestCode}`); // Expected: 400\n\n// Demonstrating a common pattern for handling HTTP responses\nfunction handleResponse(statusCode: number) {\n  const statusDescription = HTTP_STATUS_CODES[statusCode.toString() as keyof typeof HTTP_STATUS_CODES];\n  if (statusCode >= 200 && statusCode < 300) {\n    console.log(`Success: ${statusDescription}`);\n  } else if (statusCode >= 400 && statusCode < 500) {\n    console.log(`Client Error: ${statusDescription}`);\n  } else if (statusCode >= 500 && statusCode < 600) {\n    console.log(`Server Error: ${statusDescription}`);\n  }\n}\n\nhandleResponse(200);\nhandleResponse(403);\nhandleResponse(502);","lang":"typescript","description":"Demonstrates importing the enum, accessing status codes by number and description, and a practical use case in response handling."},"warnings":[{"fix":"Upgrade to version 1.0.1 or higher. If using `require()`, ensure you access the `.default` property for the ESM default export.","message":"Versions prior to 1.0.1 had an incorrect 'main' attribute in `package.json`, causing issues with CommonJS `require()` statements.","severity":"breaking","affected_versions":"<1.0.1"},{"fix":"Upgrade to version 1.0.2 or higher to ensure correct type resolution and definition files are used by TypeScript.","message":"TypeScript module resolution and type definitions were incorrect or missing in versions prior to 1.0.2, leading to compilation errors or 'any' types.","severity":"breaking","affected_versions":"<1.0.2"},{"fix":"Treat the imported `HTTP_STATUS_CODES` object as immutable. If custom status codes are needed, define a separate object or extend it carefully in your application's scope.","message":"The enum object is read-only at runtime for its core functionality. While JavaScript allows modification of object properties, directly changing values or adding new properties to `HTTP_STATUS_CODES` is not recommended and will not be type-safe or reflected in the library's intended behavior.","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":"Upgrade to `http-status-enum@1.0.2` or newer. Ensure your `tsconfig.json` has appropriate `moduleResolution` settings (e.g., `Node` or `Bundler`). For CommonJS, use `require('http-status-enum').default`.","cause":"This error most commonly occurred in versions prior to 1.0.1 due to an incorrect 'main' field in `package.json` for CommonJS environments, or prior to 1.0.2 due to missing or misconfigured TypeScript definition files.","error":"Error: Cannot find module 'http-status-enum' or its corresponding type declarations."},{"fix":"Ensure your `tsconfig.json` correctly handles `esModuleInterop` and `allowSyntheticDefaultImports`. For modern Node.js and bundlers, prefer `import HTTP_STATUS_CODES from 'http-status-enum';` (ESM) over `require()` where possible.","cause":"This TypeScript error occurs when trying to access `.default` on the result of `require()` in a TypeScript CJS context, and TypeScript's module resolution doesn't correctly infer the ESM default export.","error":"Property 'default' does not exist on type 'typeof import(\"http-status-enum\")'."},{"fix":"Use a type assertion: `HTTP_STATUS_CODES[someStringVariable as keyof typeof HTTP_STATUS_CODES]` or validate the string against the enum keys if it comes from user input.","cause":"This TypeScript error arises when trying to access `HTTP_STATUS_CODES[someStringVariable]` without type assertion, as TypeScript doesn't statically know `someStringVariable` is a valid key.","error":"Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof import(\"http-status-enum\")'."}],"ecosystem":"npm","meta_description":null}