Registry / http-networking / status-code-enum

status-code-enum

JSON →
library1.0.0jsnpmunverified

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.

npm install status-code-enum
INSTALL
IMPORT
SIG · STATUS-CODE-ENUM
S
status-code-enum
http-networkingjavascriptv1.0.0
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.

StatusCode
import { StatusCode } from 'status-code-enum'
import StatusCode from 'status-code-enum'
The `StatusCode` enum is a named export. Do not use a default import.
StatusCode
const { StatusCode } = require('status-code-enum')
const StatusCode = require('status-code-enum')
For CommonJS environments, `StatusCode` must be destructured from the `require` call as it's a named export.
StatusCode.ClientErrorBadRequest
import { StatusCode } from 'status-code-enum'; /* ... */ res.statusCode = StatusCode.ClientErrorBadRequest;
import { ClientErrorBadRequest } from 'status-code-enum'
Individual enum members are accessed via the `StatusCode` namespace, not directly imported.

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.

import { StatusCode } from 'status-code-enum'; // Example in a hypothetical HTTP response context (e.g., Node.js http module or framework) interface HttpResponse { statusCode: number; send: (message: string) => void; } const mockResponse: HttpResponse = { statusCode: 200, // Default or initial status send: (message: string) => console.log(`Sending response: ${message} (Status: ${mockResponse.statusCode})`) }; // Setting a 400 Bad Request status mockResponse.statusCode = StatusCode.ClientErrorBadRequest; mockResponse.send("Your request was malformed."); // Setting a 200 OK status mockResponse.statusCode = StatusCode.SuccessOK; mockResponse.send("Request processed successfully."); // Setting a 404 Not Found status mockResponse.statusCode = StatusCode.ClientErrorNotFound; mockResponse.send("The requested resource could not be found."); // Accessing the enum member directly const unauthorizedCode: number = StatusCode.ClientErrorUnauthorized; console.log(`Unauthorized status code is: ${unauthorizedCode}`);
Debug
Known issues
gotchaThis 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.
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.
affects: >=1.0.0
gotchaAttempting 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.
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.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: StatusCode is not defined
The `StatusCode` enum was not correctly imported before use in an ESM or CommonJS module.
fix
Ensure you are using `import { StatusCode } from 'status-code-enum';` for ESM/TypeScript or `const { StatusCode } = require('status-code-enum');` for CommonJS.
Property 'ClientErrorBadRequestt' does not exist on type 'typeof StatusCode'. Did you mean 'ClientErrorBadRequest'?
Attempted to access a non-existent or misspelled member of the `StatusCode` enum. TypeScript's strict type checking prevents this.
fix
Correct the spelling of the enum member. Use IDE auto-completion to ensure the correct member name is used (e.g., `StatusCode.ClientErrorBadRequest`).
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
6
OpenAI (training)
1
Resources
status-code-enum — npm install status-code-enum · libregistry