Registry / http-networking / http-response-status

http-response-status

JSON →
library1.1.3jsnpmunverified

This package provides a comprehensive, TypeScript-first solution for working with HTTP status codes in JavaScript and Node.js applications. It offers a structured approach to access HTTP status code constants, retrieve human-readable names, and categorize codes into their respective classes (e.g., informational, success, client error, server error). The current stable version is 1.1.3, released in December 2022. While its release cadence has been infrequent, focusing primarily on bug fixes and minor dependency updates, the library remains a reliable choice for static HTTP status code mapping. Key differentiators include its robust TypeScript typings, which ensure compile-time safety and better developer experience, and its utility functions that simplify common operations like checking status categories, providing an abstract layer over raw numerical comparisons. It serves as a lightweight and focused alternative to manually managing HTTP status code logic.

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

NHttpStatuses
import { NHttpStatuses } from 'http-response-status'
const NHttpStatuses = require('http-response-status').NHttpStatuses
Provides an enum-like object of standard HTTP status codes (e.g., NHttpStatuses.OK, NHttpStatuses.NOT_FOUND).
getHttpStatusName
import { getHttpStatusName } from 'http-response-status'
import getHttpStatusName from 'http-response-status'
A utility function to retrieve the human-readable string name for a given HTTP status code (e.g., 200 returns 'OK').
getHttpStatusCategory
import { getHttpStatusCategory } from 'http-response-status'
A utility function to categorize an HTTP status code into types like 'SUCCESS', 'CLIENT_ERROR', 'SERVER_ERROR'.
HTTP_STATUS_SUCCESS
import { HTTP_STATUS_SUCCESS } from 'http-response-status'
const HTTP_STATUS_SUCCESS = require('http-response-status').HTTP_STATUS_SUCCESS
A constant string ('SUCCESS') used to compare against the output of getHttpStatusCategory.

Demonstrates how to check specific HTTP status codes, retrieve their human-readable names, and categorize them using the provided constants and utility functions for robust response handling.

import { NHttpStatuses, getHttpStatusName, getHttpStatusCategory, HTTP_STATUS_SUCCESS, HTTP_STATUS_CLIENT_ERROR } from 'http-response-status'; function processHttpResponse(statusCode: number): string { if (statusCode === NHttpStatuses.OK) { console.log(`Status ${statusCode}: All good, operation successful!`); return 'OK'; } const statusName = getHttpStatusName(statusCode); if (statusName) { console.log(`Status ${statusCode}: ${statusName}`); } else { console.log(`Status ${statusCode}: Unknown Status Code`); } const statusCategory = getHttpStatusCategory(statusCode); if (statusCategory === HTTP_STATUS_SUCCESS) { console.log(`Category for ${statusCode} is Success.`); return 'Success'; } else if (statusCategory === HTTP_STATUS_CLIENT_ERROR) { console.log(`Category for ${statusCode} is Client Error.`); return 'Client Error'; } else { console.log(`Category for ${statusCode} is ${statusCategory || 'Other'}.`); return 'Other'; } } processHttpResponse(200); processHttpResponse(404); processHttpResponse(500); processHttpResponse(201); processHttpResponse(1000); // Example of an unknown status code
Debug
Known issues
gotchaAs of version 1.1.3, internal module paths were updated in the `package.json`. While this change typically improves module resolution in modern build systems, projects relying on older or non-standard configurations that directly referenced internal file paths (e.g., `http-response-status/dist/index.js`) might experience resolution issues or unexpected errors.
fix
Always import directly from the package root: `import { ... } from 'http-response-status'`. Avoid referencing internal file paths to ensure compatibility with future updates.
affects: >=1.1.3
gotchaThe package primarily uses ES Modules (ESM) for its exports, alongside CommonJS compatibility. Mixing ESM `import` statements with incorrect CommonJS `require()` syntax for named exports can lead to `TypeError` (e.g., 'X is undefined') or `SyntaxError` (e.g., 'Named export not found').
fix
Ensure consistent module usage within your project. For Node.js projects, set `"type": "module"` in `package.json` for ESM, or use `const { Name } = require('http-response-status');` for CJS environments.
affects: >=1.0.0
gotchaThis library is a static map of HTTP response statuses and utility functions based on standard specifications. It does not dynamically fetch or update status definitions from external sources, nor does it provide HTTP client or server functionality. Its scope is strictly limited to providing programmatic access to static HTTP status metadata.
fix
Understand that this package is purely for reference and utility around standard HTTP status codes, not for network requests or server-side routing directly. Integrate it with your existing HTTP client/server libraries.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'OK')
Attempting to destructure `NHttpStatuses` (or other named exports) from a CommonJS `require` call using incorrect syntax, often `const NHttpStatuses = require('http-response-status').NHttpStatuses` instead of correct named destructuring.
fix
For CommonJS, use `const { NHttpStatuses } = require('http-response-status');`. Alternatively, switch your project to ES Modules and use `import { NHttpStatuses } from 'http-response-status';`.
SyntaxError: Named export 'getHttpStatusName' not found. The requested module 'http-response-status' is a CommonJS module, which may not support named exports.
This error occurs when a bundler or runtime attempts to use ESM named `import` syntax (`import { getHttpStatusName } from '...'`) for a module it incorrectly identifies as purely CommonJS, or when the `package.json` `exports` field isn't correctly configured for dual-package usage in a mixed environment.
fix
Verify your project's module type configuration (`"type": "module"` in `package.json` for ESM) and your bundler settings. If targeting older Node.js or CJS, use `const { getHttpStatusName } = require('http-response-status');`.
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

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