{"id":17697,"library":"http-reasons","title":"HTTP Reason Phrase Lookup","description":"http-reasons is a minimalist JavaScript utility that provides a database to look up human-readable reason phrases for HTTP response status codes. The package is currently at version 0.1.0 and appears to be in a maintenance state, as there have been no significant updates or new releases from Postman Labs, its maintainer, for several years. Its primary function is a static data lookup, offering a simple mapping of numeric HTTP status codes to their corresponding standard reason phrases. Developers seeking more actively maintained alternatives with broader features like explicit ES module support, TypeScript definitions, and more comprehensive status code constants (e.g., `StatusCodes.OK`, `ReasonPhrases.OK`) should consider packages like `http-status-codes`, which offers a more robust and modern API.","status":"maintenance","version":"0.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/postmanlabs/http-reasons","tags":["javascript","postman","http-code","response-code","reason"],"install":[{"cmd":"npm install http-reasons","lang":"bash","label":"npm"},{"cmd":"yarn add http-reasons","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-reasons","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package primarily exports an object containing the status code mappings as its default export. While Node.js's CJS-ESM interop might allow named imports in some build setups, treating it as a default export is the safest approach.","wrong":"import { httpReasons } from 'http-reasons';","symbol":"httpReasons","correct":"import httpReasons from 'http-reasons';"},{"note":"As a CommonJS-first package, `require()` is the native way to import. It exports a direct object map, not a function like `getReason`.","wrong":"const { getReason } = require('http-reasons');","symbol":"getReason","correct":"const httpReasons = require('http-reasons');\nconst reason = httpReasons[200];"},{"note":"This package does not ship with official TypeScript type declarations. Users must provide their own declaration files (e.g., `http-reasons.d.ts`) if strong typing is desired.","wrong":"import { ReasonsMap } from 'http-reasons';","symbol":"reasonsMap","correct":"import type { ReasonsMap } from 'http-reasons/types'; // (Assuming custom type declaration)"}],"quickstart":{"code":"import httpReasons from 'http-reasons';\n\n// Look up the reason phrase for a 200 OK status code\nconst okReason = httpReasons[200];\nconsole.log(`200: ${okReason}`); // Expected: \"OK\"\n\n// Look up the reason phrase for a 404 Not Found status code\nconst notFoundReason = httpReasons[404];\nconsole.log(`404: ${notFoundReason}`); // Expected: \"Not Found\"\n\n// Attempt to look up a non-existent status code\nconst nonExistentReason = httpReasons[999];\nconsole.log(`999: ${nonExistentReason}`); // Expected: undefined\n\n// Example of using the lookup in a simple server response (conceptual)\n/*\nimport http from 'http';\n\nhttp.createServer((req, res) => {\n  const statusCode = 200; // or 404, 500, etc.\n  const reasonPhrase = httpReasons[statusCode] || 'Unknown Status';\n  res.writeHead(statusCode, reasonPhrase, { 'Content-Type': 'text/plain' });\n  res.end(`Status ${statusCode}: ${reasonPhrase}`);\n}).listen(3000, () => {\n  console.log('Server running on http://localhost:3000');\n});\n*/","lang":"javascript","description":"Demonstrates importing the http-reasons package and looking up reason phrases for various HTTP status codes, including a non-existent one, and conceptual server usage."},"warnings":[{"fix":"For projects requiring active maintenance, TypeScript support, or explicit ESM modules, consider alternatives like `http-status-codes`.","message":"The `http-reasons` package is at an early version (0.1.0) and has not been updated in several years by Postman Labs. This indicates a lack of active maintenance, meaning bug fixes, new features, or compatibility updates for newer Node.js versions or standards are unlikely.","severity":"gotcha","affected_versions":"0.1.0"},{"fix":"Use `const httpReasons = require('http-reasons');` for CommonJS projects. For ES Module projects, treat it as a default import (`import httpReasons from 'http-reasons';`) and ensure your build tools (e.g., Webpack, Rollup) are configured to handle CJS dependencies in an ESM context. Or use a native ESM alternative.","message":"This package was developed in a CommonJS-first era. While Node.js offers some interoperability, direct `import` statements in an ES Module context might require specific build configurations or lead to `ERR_REQUIRE_ESM` errors if not handled correctly. It does not explicitly define `exports` in its `package.json`.","severity":"breaking","affected_versions":"0.1.0"},{"fix":"Create a custom declaration file (e.g., `types/http-reasons.d.ts`) to provide type definitions for the exported object, or use a typed alternative package.","message":"The package does not ship with official TypeScript type definitions (`.d.ts` files). This means TypeScript users will not get type safety or autocompletion for the `httpReasons` object by default, potentially leading to runtime errors if incorrect keys are accessed.","severity":"gotcha","affected_versions":"0.1.0"},{"fix":"Access reason phrases using bracket notation for property lookup: `httpReasons[statusCode]`.","message":"The package exports a static object, not a function. Attempting to call `httpReasons(200)` will result in a `TypeError`, as it's designed for direct property access (e.g., `httpReasons[200]`).","severity":"gotcha","affected_versions":"0.1.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Access the reason phrase using bracket notation: `const reason = httpReasons[200];`","cause":"Attempting to call the imported `httpReasons` object as a function, rather than accessing its properties.","error":"TypeError: httpReasons is not a function"},{"fix":"Install `@types/http-reasons` if it exists (unlikely for an unmaintained package) or create a manual declaration file, for example, `declare module 'http-reasons';` as a quick fix, or provide more specific types if needed.","cause":"The `http-reasons` package does not include TypeScript type definitions by default.","error":"TS2307: Cannot find module 'http-reasons' or its corresponding type declarations."},{"fix":"Ensure your project's module system is consistent. If using ESM, try `import httpReasons from 'http-reasons';`. If using CJS, stick to `const httpReasons = require('http-reasons');`. Consider setting `\"type\": \"module\"` in your `package.json` for new ESM projects and adjusting imports/exports accordingly.","cause":"Attempting to `require()` an ES Module in a CommonJS context, or vice-versa, when `http-reasons` is likely CJS-only.","error":"ERR_REQUIRE_ESM: require() of ES Module ... not supported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}