{"id":16389,"library":"http-status-response-codes","title":"HTTP Status Code Utilities","description":"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.","status":"maintenance","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/KaustubhKhati/http-status-codes","tags":["javascript","http","nodejs","statuscode"],"install":[{"cmd":"npm install http-status-response-codes","lang":"bash","label":"npm"},{"cmd":"yarn add http-status-response-codes","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-status-response-codes","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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).","wrong":"import HttpStatus from 'http-status-response-codes';","symbol":"HttpStatus","correct":"const HttpStatus = require('http-status-response-codes');"},{"note":"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.","wrong":"import { statusCodes } from 'http-status-response-codes';","symbol":"statusCodes","correct":"const { statusCodes } = require('http-status-response-codes');"},{"note":"These are instance methods on the `HttpStatus` class, not direct exports. Ensure you instantiate the class first.","symbol":"is2xxSuccessful","correct":"const httpStatus = new HttpStatus('200'); httpStatus.is2xxSuccessful();"}],"quickstart":{"code":"const HttpStatus = require('http-status-response-codes');\nconst { statusCodes } = require('http-status-response-codes');\n\nasync function demonstrateHttpStatus() {\n  // Example 1: Instantiate with a numeric string\n  const notFoundStatus = new HttpStatus('404');\n  console.log(`Code: ${notFoundStatus.getCodeValue()} Name: ${notFoundStatus.getName()}`);\n  console.log(`Is client error? ${notFoundStatus.is4xxClientError()}`); // true\n  console.log(`Is error? ${notFoundStatus.isError()}`); // true\n  console.log(`Description: ${notFoundStatus.getDescription()}`);\n\n  // Example 2: Instantiate with a mock response object (simulating an HTTP client response)\n  // The package expects an object with a '.status' property, similar to older libraries like request-promise.\n  const mockSuccessResponse = { status: 200, body: 'OK' }; // Mock a response object\n  const successStatus = new HttpStatus(mockSuccessResponse);\n  console.log(`Code: ${successStatus.getCodeValue()} Name: ${successStatus.getName()}`);\n  console.log(`Is successful? ${successStatus.is2xxSuccessful()}`); // true\n  console.log(`Is error? ${successStatus.isError()}`); // false\n\n  // Example 3: Accessing the statusCodes enum for numerical values\n  console.log(`HTTP_BAD_REQUEST: ${statusCodes.BAD_REQUEST}`); // 400\n  console.log(`HTTP_INTERNAL_SERVER_ERROR: ${statusCodes.INTERNAL_SERVER_ERROR}`); // 500\n\n  // Using a simulated server error response\n  const simulatedResponse = { status: 503, statusText: 'Service Unavailable' };\n  const serverErrorStatus = new HttpStatus(simulatedResponse);\n  if (serverErrorStatus.isError()) {\n    console.log(`\nCaught an HTTP error: ${serverErrorStatus.getCodeValue()} - ${serverErrorStatus.getDescription()}`);\n    console.log(`Is server error? ${serverErrorStatus.is5xxServerError()}`); // true\n  }\n}\n\ndemonstrateHttpStatus();","lang":"javascript","description":"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."},"warnings":[{"fix":"Use `const HttpStatus = require('http-status-response-codes');` and `const { statusCodes } = require('http-status-response-codes');` for all imports.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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 })`.","message":"The `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`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Evaluate against more actively maintained alternatives if up-to-date features, comprehensive type support, or continuous maintenance are critical for your project.","message":"The 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).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.2':14 'activ':137 'addit':84 'appear':127 'boot':30 'categor':65 'centric':123 'class':36 'classif':109 'code':3,10,23,45,68,80,102 'collect':97 'commonj':122 'commonjs-centr':121 'complet':134 'contain':55 'conveni':93 'current':12 'descript':83 'draw':24 'e.g':69 'enum':95 'enum-lik':94 'evolut':141 'exampl':124 'export':33,87 'facilit':105 'featur':133 'feature-complet':132 'framework':31 'given':117 'handl':20,107 'http':1,7,21,100,111,143 'http-status-response-cod':6 'httpstatus':35,61 'inspir':25 'instanc':59 'instanti':40 'is1xxinformational':73 'is2xxsuccessful':70 'is3xxredirection':74 'is4xxclienterror':71 'is5xxservererror':75 'iserror':72 'java':27 'javascript':17,140,142 'librari':104 'like':53,96 'manner':116 'method':63 'modern':139 'name':79 'nodej':144 'numer':43 'object':54,90 'offer':62 'packag':11,86,126 'programmat':106 'properti':58 'provid':15,91 'respons':9,52,112 'response-lik':51 'retriev':77 'spring':29 'stabl':130 'standard':99 'status':2,8,22,44,57,67,101 'statuscod':89,145 'string':48 'structur':115 'undergo':138 'util':4,18 'valu':81 'version':13,119","created_at":"2026-04-22T04:50:08.555349+00:00","updated_at":"2026-04-22T04:50:08.555349+00:00","problems":[{"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 }`).","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'status')"},{"fix":"The `HttpStatus` class is the default export. Use `const HttpStatus = require('http-status-response-codes');` to import it correctly.","cause":"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).","error":"TypeError: HttpStatus is not a constructor"},{"fix":"For CommonJS, use `const { statusCodes } = require('http-status-response-codes');` to correctly destructure the named export.","cause":"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.","error":"SyntaxError: Named export 'statusCodes' not found. The requested module 'http-status-response-codes' does not provide an export named 'statusCodes'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/KaustubhKhati/http-status-codes","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/http-status-response-codes","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","web-framework","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-21","install_tag":null}}