{"id":17264,"library":"http-response-status","title":"HTTP Status Map","description":"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.","status":"active","version":"1.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/arnaud-zg/http-response-status","tags":["javascript","http","typescript","code","response","status"],"install":[{"cmd":"npm install http-response-status","lang":"bash","label":"npm"},{"cmd":"yarn add http-response-status","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-response-status","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Provides an enum-like object of standard HTTP status codes (e.g., NHttpStatuses.OK, NHttpStatuses.NOT_FOUND).","wrong":"const NHttpStatuses = require('http-response-status').NHttpStatuses","symbol":"NHttpStatuses","correct":"import { NHttpStatuses } from 'http-response-status'"},{"note":"A utility function to retrieve the human-readable string name for a given HTTP status code (e.g., 200 returns 'OK').","wrong":"import getHttpStatusName from 'http-response-status'","symbol":"getHttpStatusName","correct":"import { getHttpStatusName } from 'http-response-status'"},{"note":"A utility function to categorize an HTTP status code into types like 'SUCCESS', 'CLIENT_ERROR', 'SERVER_ERROR'.","symbol":"getHttpStatusCategory","correct":"import { getHttpStatusCategory } from 'http-response-status'"},{"note":"A constant string ('SUCCESS') used to compare against the output of getHttpStatusCategory.","wrong":"const HTTP_STATUS_SUCCESS = require('http-response-status').HTTP_STATUS_SUCCESS","symbol":"HTTP_STATUS_SUCCESS","correct":"import { HTTP_STATUS_SUCCESS } from 'http-response-status'"}],"quickstart":{"code":"import { NHttpStatuses, getHttpStatusName, getHttpStatusCategory, HTTP_STATUS_SUCCESS, HTTP_STATUS_CLIENT_ERROR } from 'http-response-status';\n\nfunction processHttpResponse(statusCode: number): string {\n  if (statusCode === NHttpStatuses.OK) {\n    console.log(`Status ${statusCode}: All good, operation successful!`);\n    return 'OK';\n  }\n\n  const statusName = getHttpStatusName(statusCode);\n  if (statusName) {\n    console.log(`Status ${statusCode}: ${statusName}`);\n  } else {\n    console.log(`Status ${statusCode}: Unknown Status Code`);\n  }\n\n  const statusCategory = getHttpStatusCategory(statusCode);\n  if (statusCategory === HTTP_STATUS_SUCCESS) {\n    console.log(`Category for ${statusCode} is Success.`);\n    return 'Success';\n  } else if (statusCategory === HTTP_STATUS_CLIENT_ERROR) {\n    console.log(`Category for ${statusCode} is Client Error.`);\n    return 'Client Error';\n  } else {\n    console.log(`Category for ${statusCode} is ${statusCategory || 'Other'}.`);\n    return 'Other';\n  }\n}\n\nprocessHttpResponse(200);\nprocessHttpResponse(404);\nprocessHttpResponse(500);\nprocessHttpResponse(201);\nprocessHttpResponse(1000); // Example of an unknown status code","lang":"typescript","description":"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."},"warnings":[{"fix":"Always import directly from the package root: `import { ... } from 'http-response-status'`. Avoid referencing internal file paths to ensure compatibility with future updates.","message":"As 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.","severity":"gotcha","affected_versions":">=1.1.3"},{"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.","message":"The 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').","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"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';`.","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'OK')"},{"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');`.","cause":"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.","error":"SyntaxError: Named export 'getHttpStatusName' not found. The requested module 'http-response-status' is a CommonJS module, which may not support named exports."}],"ecosystem":"npm","meta_description":null}