Registry / http-networking / http-response-status-code

http-response-status-code

JSON →
library1.7.5jsnpmunverified

This package, `http-response-status-code`, provides a lightweight and comprehensive utility for interacting with HTTP status codes, names, and descriptions. Currently at version 1.7.5, it offers a stable API for retrieving details, validating codes, and categorizing them into informational, success, redirection, client error, and server error groups. The library differentiates itself by providing a full suite of helper functions, such as `getStatusName`, `getStatusDescription`, `getNotFound`, and dedicated checks like `isInformationalCode` or `isClientErrorCode`, in addition to exposing all standard HTTP status codes as named exports. Its release cadence appears to be moderate, with minor updates focusing on feature additions like the "Toolset Overview" in 1.7.2 and continuous code hygiene improvements. It ships with TypeScript types, ensuring robust usage in modern JavaScript and TypeScript environments, making it a reliable choice for handling HTTP response logic.

npm install http-response-status-code
INSTALL
IMPORT
SIG · HTTP-RESPONSE-STAT
H
http-response-status-code
http-networkingjavascriptv1.7.5
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.

STATUS_CODES
import * as STATUS_CODES from 'http-response-status-code';
const STATUS_CODES = require('http-response-status-code');
Use this for CommonJS environments or to import all exports as a namespace in ESM.
OK
import { OK, getStatusName, CODES } from 'http-response-status-code';
import STATUS_CODES from 'http-response-status-code'; STATUS_CODES.OK;
All individual status codes (e.g., OK, NOT_FOUND) and core utility functions are exported as named exports. This is the recommended ESM approach.
getStatusName
import { getStatusName } from 'http-response-status-code';
import * as STATUS_CODES from 'http-response-status-code'; STATUS_CODES.getStatName(...);
Be mindful of exact function names; typos can lead to runtime errors.

This example demonstrates how to import and use various utilities to retrieve status codes, names, descriptions, and check code categories.

import { OK, NOT_FOUND, isSuccessCode, getStatusName, getStatusDescription, getNotFound, getStatusCode, CLIENT_ERROR_CODES } from 'http-response-status-code'; console.log('OK status code:', OK); // 200 console.log('Not Found status code:', NOT_FOUND); // 404 const status200Name = getStatusName(OK); console.log('Name for 200:', status200Name); // OK const status404Description = getStatusDescription(NOT_FOUND); console.log('Description for 404:', status404Description); // Not Found const nameForNotFound = getNotFound().name; console.log('Name from getNotFound():', nameForNotFound); // Not Found const codeForOK = getStatusCode('OK'); console.log('Code for "OK":', codeForOK); // 200 console.log('Is 200 a success code?', isSuccessCode(OK)); // true console.log('Is 404 a success code?', isSuccessCode(NOT_FOUND)); // false console.log('First 5 client error codes:', CLIENT_ERROR_CODES.slice(0, 5)); // [400, 401, 402, 403, 404]
Debug
Known issues
gotchaThe release notes for v1.7.2 contain a typo in the `getStat` example, which is incomplete and incorrect. The correct function names are `getStatusName` or `getStatusCode`.
fix
Ensure you are calling the correct function, e.g., `STATUS_CODES.getStatusName(STATUS_CODES.OK)` or `STATUS_CODES.getStatusCode('OK')`.
affects: >=1.7.2
gotchaWhen migrating from CommonJS `require` to ESM `import`, ensure you use named imports for specific codes and functions (e.g., `import { OK, getStatusName } from 'pkg'`) or a namespace import (`import * as STATUS_CODES from 'pkg'`) if you want to access all exports under a single object.
fix
Avoid `import STATUS_CODES from 'pkg'` as a default import is not provided, which will result in `undefined`.
affects: >=1.0.0
gotchaThe library primarily uses full upper-case strings for status code names (e.g., 'OK', 'NOT FOUND') when functions like `getStatusCode` are expecting a string input. Mismatched casing might lead to unexpected results.
fix
Always use the exact upper-case string name as defined in HTTP standards, or refer to the library's `CODES` object for a definitive list.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: STATUS_CODES.getStat is not a function
Attempting to use a non-existent function name, possibly copied from an incomplete example in release notes.
fix
Correct the function call to `STATUS_CODES.getStatusName` or `STATUS_CODES.getStatusCode`.
TypeError: Cannot read properties of undefined (reading 'OK')
Incorrect ESM import syntax, attempting to use a default import when only named or namespace imports are available.
fix
Change your import statement to `import { OK } from 'http-response-status-code';` for specific codes or `import * as STATUS_CODES from 'http-response-status-code';` to access all exports via `STATUS_CODES.OK`.
Upgrade
Version history
1.7.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
12
Resources
http-response-status-code — npm install http-response-status-code · libregistry