Registry / http-networking / http-status-response-codes

http-status-response-codes

JSON →
library1.0.2jsnpmunverified

The `http-status-response-codes` package (current version 1.0.2) provides a JavaScript utility for handling HTTP status codes, drawing inspiration from Java's Spring Boot framework. It exports an `HttpStatus` class that can be instantiated with a numeric status code (as a string) or a response-like object containing a `status` property. Instances of `HttpStatus` offer methods to categorize the status code (e.g., `is2xxSuccessful()`, `is4xxClientError()`, `isError()`, `is1xxInformational()`, `is3xxRedirection()`, `is5xxServerError()`), and retrieve its name, code value, and description. Additionally, the package exports a `statusCodes` object, providing a convenient enum-like collection of standard HTTP status codes. This library facilitates programmatic handling and classification of HTTP responses in a structured manner. Given its version and CommonJS-centric examples, the package appears to be stable and feature-complete, but not actively undergoing modern JavaScript evolution.

npm install http-status-response-codes
INSTALL
IMPORT
SIG · HTTP-STATUS-RESPON
H
http-status-response-codes
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.

HttpStatus
const HttpStatus = require('http-status-response-codes');
import HttpStatus from 'http-status-response-codes';
The package primarily uses CommonJS. Direct ESM `import` statements may not work or could require specific Node.js configuration (e.g., using a CommonJS wrapper).
statusCodes
const { statusCodes } = require('http-status-response-codes');
import { statusCodes } from 'http-status-response-codes';
Access to the `statusCodes` enum is via named CommonJS `require` destructuring. ESM imports are not directly supported by the examples or implied by the package's age.
is2xxSuccessful
const httpStatus = new HttpStatus('200'); httpStatus.is2xxSuccessful();
These are instance methods on the `HttpStatus` class, not direct exports. Ensure you instantiate the class first.

This quickstart demonstrates how to instantiate `HttpStatus` with both a string and a mock response object, how to use its categorization methods (`is4xxClientError`, `is2xxSuccessful`, `isError`), and how to access specific status code values from the `statusCodes` object. It highlights common usage patterns for checking HTTP response types.

const HttpStatus = require('http-status-response-codes'); const { statusCodes } = require('http-status-response-codes'); async function demonstrateHttpStatus() { // Example 1: Instantiate with a numeric string const notFoundStatus = new HttpStatus('404'); console.log(`Code: ${notFoundStatus.getCodeValue()} Name: ${notFoundStatus.getName()}`); console.log(`Is client error? ${notFoundStatus.is4xxClientError()}`); // true console.log(`Is error? ${notFoundStatus.isError()}`); // true console.log(`Description: ${notFoundStatus.getDescription()}`); // Example 2: Instantiate with a mock response object (simulating an HTTP client response) // The package expects an object with a '.status' property, similar to older libraries like request-promise. const mockSuccessResponse = { status: 200, body: 'OK' }; // Mock a response object const successStatus = new HttpStatus(mockSuccessResponse); console.log(`Code: ${successStatus.getCodeValue()} Name: ${successStatus.getName()}`); console.log(`Is successful? ${successStatus.is2xxSuccessful()}`); // true console.log(`Is error? ${successStatus.isError()}`); // false // Example 3: Accessing the statusCodes enum for numerical values console.log(`HTTP_BAD_REQUEST: ${statusCodes.BAD_REQUEST}`); // 400 console.log(`HTTP_INTERNAL_SERVER_ERROR: ${statusCodes.INTERNAL_SERVER_ERROR}`); // 500 // Using a simulated server error response const simulatedResponse = { status: 503, statusText: 'Service Unavailable' }; const serverErrorStatus = new HttpStatus(simulatedResponse); if (serverErrorStatus.isError()) { console.log(` Caught an HTTP error: ${serverErrorStatus.getCodeValue()} - ${serverErrorStatus.getDescription()}`); console.log(`Is server error? ${serverErrorStatus.is5xxServerError()}`); // true } } demonstrateHttpStatus();
Debug
Known issues
gotchaThe package is predominantly CommonJS (CJS) as indicated by all examples using `require()`. Attempting to use ESM `import` statements directly might lead to runtime errors or require specific build tool configurations, as the package may not explicitly export ESM modules.
fix
Use `const HttpStatus = require('http-status-response-codes');` and `const { statusCodes } = require('http-status-response-codes');` for all imports.
affects: >=1.0.0
gotchaThe `HttpStatus` constructor can accept a 'Response Object' as input, but the exact structure is implicitly tied to older HTTP client libraries (e.g., `request-promise` used in the README's main example). Modern `fetch` API or `axios` response objects might require manually extracting the `status` property before passing it to `HttpStatus`.
fix
Ensure the object passed to `new HttpStatus()` has a `status` property containing the numeric HTTP status code, e.g., `new HttpStatus({ status: response.status })`.
affects: >=1.0.0
gotchaThe package appears to be in a maintenance mode. It has a low version number (1.0.2) and the provided examples use older JavaScript patterns and libraries (like `request-promise`). While functional, it might not receive updates for new HTTP status codes, security patches, or modern JavaScript features (like TypeScript definitions or native ESM support).
fix
Evaluate against more actively maintained alternatives if up-to-date features, comprehensive type support, or continuous maintenance are critical for your project.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'status')
The `HttpStatus` constructor was called with an `undefined` or `null` value, or an object missing a `status` property, when attempting to extract the status code.
fix
Ensure the argument passed to `new HttpStatus()` is either a valid numeric string (e.g., `'200'`) or an object with a `status` property (e.g., `{ status: 200 }`).
TypeError: HttpStatus is not a constructor
Attempting to use `HttpStatus` as a class constructor after an incorrect import (e.g., `const HttpStatus = require('http-status-response-codes').HttpStatus;` instead of directly `require`ing the default export).
fix
The `HttpStatus` class is the default export. Use `const HttpStatus = require('http-status-response-codes');` to import it correctly.
SyntaxError: Named export 'statusCodes' not found. The requested module 'http-status-response-codes' does not provide an export named 'statusCodes'
Attempting to use ESM `import { statusCodes } from 'http-status-response-codes';` in a CommonJS-only environment or for a package that does not explicitly support ESM named exports.
fix
For CommonJS, use `const { statusCodes } = require('http-status-response-codes');` to correctly destructure the named export.
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-response-codes — npm install http-status-response-codes · libregistry