http-status is a utility library for Node.js that provides comprehensive interaction with HTTP status codes, their names, messages, and classes. Currently at version 2.1.0, it offers a stable API for looking up information by either a numeric code or a symbolic name (e.g., `status[404]` or `status.NOT_FOUND`). A key differentiator is its inclusion of both standard IANA codes and an extensive set of 'extra' codes used by popular software like IIS, NGINX, and Cloudflare, which are categorized and accessible. The library is written in TypeScript and supports both ESM and CommonJS module systems, with a focus on ease of use across modern JavaScript environments. It doesn't specify a strict release cadence but shows active maintenance through its recent major version migration to modern module standards.
npm install http-statusVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to retrieve HTTP status code names, messages, and classes by both numeric code and symbolic name, including access to 'extra' status codes and class metadata.
For CommonJS, use `const { default: status } = require('http-status');` or `const status = require('http-status').default;`. For named exports, `const { NOT_FOUND } = require('http-status');` is correct.Understand the API structure: `status[CODE]` gives the name, `status.NAME` gives the message, `status.NAME_CODE` gives the number. `status[CODE_NAME]` and `status[CODE_MESSAGE]` provide explicit access to the name and message respectively, similar to `status.NAME` and `status.NAME_CODE`.
To access specific extra codes, use `status.extra.cloudflare[520]` or `status.extra.nginx.NO_RESPONSE_CODE`. Alternatively, `import extraStatus from 'http-status/extra/cloudflare'` allows direct access to those codes, which are merged with common HTTP statuses in the imported object.
Update CommonJS import: `const { default: status } = require('http-status');` or `const status = require('http-status').default;`.If you want the main `status` object, use `import status from 'http-status';`. If you truly want a named export, ensure it's specifically exported (e.g., `OK_CODE` or `NOT_FOUND` are indeed named exports, so `import { NOT_FOUND } from 'http-status'` is correct). This error often implies confusion between default and named exports.No dependency data recorded yet.