Registry / http-networking / http-status-enum

http-status-enum

JSON →
library1.0.2jsnpmunverified

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.

npm install http-status-enum
INSTALL
IMPORT
SIG · HTTP-STATUS-ENUM
H
http-status-enum
http-networkingjavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HTTP_STATUS_CODES
import HTTP_STATUS_CODES from 'http-status-enum';
import { HTTP_STATUS_CODES } from 'http-status-enum';
The library exports a default enum object. Named imports will result in undefined.
HTTP_STATUS_CODES (CommonJS)
const HTTP_STATUS_CODES = require('http-status-enum').default;
const HTTP_STATUS_CODES = require('http-status-enum');
When consuming an ESM default export from CommonJS, the `.default` property must be accessed. This was resolved for CJS with v1.0.1.
TypeOfHttpStatusCodes
type HttpStatusCodeMap = typeof HTTP_STATUS_CODES;
To explicitly type variables that store the enum or subsets, use `typeof HTTP_STATUS_CODES` as the type for the imported enum object.

Demonstrates importing the enum, accessing status codes by number and description, and a practical use case in response handling.

import HTTP_STATUS_CODES from 'http-status-enum'; // Accessing status description by numeric code const internalServerErrorDesc = HTTP_STATUS_CODES['500']; console.log(`Description for 500: ${internalServerErrorDesc}`); // Expected: INTERNAL_SERVER_ERROR const notFoundDesc = HTTP_STATUS_CODES['404']; console.log(`Description for 404: ${notFoundDesc}`); // Expected: NOT_FOUND // Accessing numeric code by string description const okCode = HTTP_STATUS_CODES.OK; console.log(`Code for OK: ${okCode}`); // Expected: 200 const badRequestCode = HTTP_STATUS_CODES.BAD_REQUEST; console.log(`Code for BAD_REQUEST: ${badRequestCode}`); // Expected: 400 // Demonstrating a common pattern for handling HTTP responses function handleResponse(statusCode: number) { const statusDescription = HTTP_STATUS_CODES[statusCode.toString() as keyof typeof HTTP_STATUS_CODES]; if (statusCode >= 200 && statusCode < 300) { console.log(`Success: ${statusDescription}`); } else if (statusCode >= 400 && statusCode < 500) { console.log(`Client Error: ${statusDescription}`); } else if (statusCode >= 500 && statusCode < 600) { console.log(`Server Error: ${statusDescription}`); } } handleResponse(200); handleResponse(403); handleResponse(502);
Debug
Known issues
breakingVersions prior to 1.0.1 had an incorrect 'main' attribute in `package.json`, causing issues with CommonJS `require()` statements.
fix
Upgrade to version 1.0.1 or higher. If using `require()`, ensure you access the `.default` property for the ESM default export.
affects: <1.0.1
breakingTypeScript module resolution and type definitions were incorrect or missing in versions prior to 1.0.2, leading to compilation errors or 'any' types.
fix
Upgrade to version 1.0.2 or higher to ensure correct type resolution and definition files are used by TypeScript.
affects: <1.0.2
gotchaThe 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.
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.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'http-status-enum' or its corresponding type declarations.
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.
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`.
Property 'default' does not exist on type 'typeof import("http-status-enum")'.
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.
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.
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof import("http-status-enum")'.
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.
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.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
http-status-enum — npm install http-status-enum · libregistry