http-status-codes is a JavaScript/TypeScript library that provides constants for HTTP status codes and their corresponding reason phrases. It is currently at version 2.3.0 and maintains a regular release cadence, primarily adding new RFC-defined status codes and minor improvements. Key differentiators include its complete lack of external dependencies, its full support for modern JavaScript and TypeScript environments, and its comprehensive coverage of status codes defined across various RFCs (like RFC1945, RFC2616, RFC2518, RFC6585, RFC7538, RFC8297, RFC7231, RFC7540). The library is designed to be highly tree-shakable, reducing bundle sizes for applications only using a subset of its features. It also offers utility functions to retrieve reason phrases from codes and vice versa, making it a robust and convenient tool for handling HTTP responses.
npm install http-status-codesVerified import paths — ran on the pinned version, not inferred.
Demonstrates importing and using status code constants, reason phrases, and utility functions to manage HTTP responses.
Replace all instances of `getStatusText` with `getReasonPhrase`.
Update any logic that checks for the `500` reason phrase to use `ReasonPhrases.INTERNAL_SERVER_ERROR` or the string 'Internal Server Error'.
Ensure your build setup correctly handles TypeScript declarations if you are consuming this library in a non-TypeScript project or an older TypeScript environment.
Upgrade to `http-status-codes@2.1.4` or newer to benefit from improved tree-shaking and reduced bundle sizes.
Rename `getStatusText` to `getReasonPhrase`. Example: `import { getReasonPhrase } from 'http-status-codes';`For CommonJS, use `const { StatusCodes } = require('http-status-codes');` or `const StatusCodes = require('http-status-codes').StatusCodes;`. For ESM, ensure `import { StatusCodes } from 'http-status-codes';` is used.Use named imports: `import { StatusCodes } from 'http-status-codes';`.No dependency data recorded yet.