Registry / http-networking / http-reasons

http-reasons

JSON →
library0.1.0jsnpmunverified

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.

npm install http-reasons
INSTALL
IMPORT
SIG · HTTP-REASONS
H
http-reasons
http-networkingjavascriptv0.1.0
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.

httpReasons
import httpReasons from 'http-reasons';
import { httpReasons } from 'http-reasons';
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.
getReason
const httpReasons = require('http-reasons'); const reason = httpReasons[200];
const { getReason } = require('http-reasons');
As a CommonJS-first package, `require()` is the native way to import. It exports a direct object map, not a function like `getReason`.
reasonsMap
import type { ReasonsMap } from 'http-reasons/types'; // (Assuming custom type declaration)
import { ReasonsMap } from 'http-reasons';
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.

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.

import httpReasons from 'http-reasons'; // Look up the reason phrase for a 200 OK status code const okReason = httpReasons[200]; console.log(`200: ${okReason}`); // Expected: "OK" // Look up the reason phrase for a 404 Not Found status code const notFoundReason = httpReasons[404]; console.log(`404: ${notFoundReason}`); // Expected: "Not Found" // Attempt to look up a non-existent status code const nonExistentReason = httpReasons[999]; console.log(`999: ${nonExistentReason}`); // Expected: undefined // Example of using the lookup in a simple server response (conceptual) /* import http from 'http'; http.createServer((req, res) => { const statusCode = 200; // or 404, 500, etc. const reasonPhrase = httpReasons[statusCode] || 'Unknown Status'; res.writeHead(statusCode, reasonPhrase, { 'Content-Type': 'text/plain' }); res.end(`Status ${statusCode}: ${reasonPhrase}`); }).listen(3000, () => { console.log('Server running on http://localhost:3000'); }); */
Debug
Known issues
gotchaThe `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.
fix
For projects requiring active maintenance, TypeScript support, or explicit ESM modules, consider alternatives like `http-status-codes`.
affects: 0.1.0
breakingThis 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`.
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.
affects: 0.1.0
gotchaThe 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.
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.
affects: 0.1.0
gotchaThe 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]`).
fix
Access reason phrases using bracket notation for property lookup: `httpReasons[statusCode]`.
affects: 0.1.0
Errors
Common errors & fixes
TypeError: httpReasons is not a function
Attempting to call the imported `httpReasons` object as a function, rather than accessing its properties.
fix
Access the reason phrase using bracket notation: `const reason = httpReasons[200];`
TS2307: Cannot find module 'http-reasons' or its corresponding type declarations.
The `http-reasons` package does not include TypeScript type definitions by default.
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.
ERR_REQUIRE_ESM: require() of ES Module ... not supported
Attempting to `require()` an ES Module in a CommonJS context, or vice-versa, when `http-reasons` is likely CJS-only.
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.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources