Registry / http-networking / http-sts

http-sts

JSON →
library1.1.4jsnpmunverified

http-sts (HTTP Status Codes) is a JavaScript/TypeScript library designed to provide a comprehensive and structured collection of HTTP status codes. It maps each code to an object containing its numeric value, a human-readable name, and a detailed description directly sourced from MDN Web Docs. Currently at version 1.1.4, the package offers a stable and reliable way to access information for a wide range of HTTP responses, from informational (1xx) to server error (5xx) codes. Unlike simpler enumeration libraries, http-sts provides rich, descriptive content for each status code, making it suitable for applications that require more than just the code number or a basic name. Its release cadence is generally stable, with updates primarily reflecting changes or additions to HTTP status codes on MDN. Key differentiators include the depth of information provided and its direct lineage from an authoritative source like MDN, ensuring accuracy and detail.

npm install http-sts
INSTALL
IMPORT
SIG · HTTP-STS
H
http-sts
http-networkingjavascriptv1.1.4
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.

HTTPStatusCodes
import { HTTPStatusCodes } from 'http-sts';
const HTTPStatusCodes = require('http-sts').HTTPStatusCodes;
This is the main object containing all status code definitions as named properties (e.g., `CODE_200`). Modern projects should prefer ESM imports.
HTTPStatusCodeType
import type { HTTPStatusCodeType } from 'http-sts';
import { HTTPStatusCodeType } from 'http-sts';
Use `import type` for importing only the TypeScript type definition, preventing it from being bundled into JavaScript output.
CODE_200
import { CODE_200 } from 'http-sts';
import HTTPStatusCodes from 'http-sts'; console.log(HTTPStatusCodes.CODE_200);
Individual status code objects can be imported directly if only a few specific codes are needed, improving tree-shaking.

Demonstrates how to import and access individual HTTP status code objects, including their code, name, and description. It also shows how to iterate through all available codes and conceptual usage in a web server context.

import { HTTPStatusCodes, HTTPStatusCodeType } from 'http-sts'; // Access a specific status code object const okStatus: HTTPStatusCodeType = HTTPStatusCodes.CODE_200; console.log(`Code: ${okStatus.code}`); console.log(`Name: ${okStatus.name}`); console.log(`Description: ${okStatus.description}`); // Iterate over all available status codes (for documentation or internal mapping) console.log('\nAll HTTP Status Codes:'); for (const key in HTTPStatusCodes) { const statusCode = HTTPStatusCodes[key as keyof typeof HTTPStatusCodes]; console.log(`- ${statusCode.code}: ${statusCode.name}`); } // Example of using a specific code in a response (conceptual, depends on framework) function sendResponse(res: any, status: HTTPStatusCodeType, message: string) { console.log(` Sending response with status ${status.code} - ${status.name}: ${message}`); // In a real scenario: res.status(status.code).send(message); } sendResponse({}, HTTPStatusCodes.CODE_404, 'Resource not found.');
Debug
Known issues
gotchaDirect numeric access like `HTTPStatusCodes[200]` will not work as expected. Status codes are exposed as named properties, e.g., `HTTPStatusCodes.CODE_200`.
fix
Always access status codes using their `CODE_XXX` property names (e.g., `HTTPStatusCodes.CODE_404`). If you need to map a number to a code, you'll need to create a helper function or map over the `HTTPStatusCodes` object.
affects: >=1.0.0
gotchaThe descriptions provided are direct extracts from MDN Web Docs. While generally stable, they are subject to changes on MDN and are embedded at the time of the package's release. Relying on the *exact* string content for parsing or strict comparisons is not recommended.
fix
Use the `code` and `name` properties for programmatic logic. Treat `description` as display-only content. Periodically update the package to get the latest MDN descriptions.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'name')
Attempting to access a status code that does not exist or using incorrect property access (e.g., `HTTPStatusCodes.CODE_999` or `HTTPStatusCodes[200].name`).
fix
Ensure you are using a valid `CODE_XXX` property name from the `HTTPStatusCodes` object. Verify the status code actually exists in the library. If using a numeric value, ensure it's correctly mapped to its `CODE_XXX` string representation.
ReferenceError: require is not defined
Attempting to use `require()` syntax in an ESM-only context (e.g., a modern Node.js module with `"type": "module"` in `package.json` or a browser environment).
fix
Switch to ESM `import` statements: `import { HTTPStatusCodes } from 'http-sts';`. Ensure your project is configured for ESM if you intend to use it, or stick to CommonJS `require` if your environment explicitly supports it.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
http-sts — npm install http-sts · libregistry