HTTP Status Codes Utility

2.1.0 · active · verified Tue Apr 21

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import status from 'http-status';

console.log('--- Standard HTTP Status Codes ---');
// Look up status message by code
console.log('200 Name:', status[200_NAME]); // Outputs: OK
console.log('404 Message:', status[404_MESSAGE]); // Outputs: Not Found
console.log('500 Class:', status[500_CLASS]); // Outputs: SERVER_ERROR

// Look up code or message by status name
console.log('OK Code:', status.OK_CODE); // Outputs: 200
console.log('IM_A_TEAPOT Message:', status.IM_A_TEAPOT); // Outputs: I'm a teapot

console.log('\n--- Status Code Classes ---');
// Access status code classes
console.log('1xx Class Name:', status.classes[1].name); // Outputs: Informational
console.log('2xx Message:', status.classes.SUCCESSFUL_MESSAGE); // Outputs: Successful

console.log('\n--- Extra Status Codes (Cloudflare) ---');
// Access extra status codes via `extra` property
console.log('Cloudflare 520:', status.extra.cloudflare[520_MESSAGE]); // Outputs: Unknown Error
console.log('Cloudflare NO_RESPONSE Code:', status.extra.cloudflare.NO_RESPONSE_CODE); // Outputs: 444

// Example of directly importing extra codes (requires separate import statement or direct require)
// import cloudflareStatus from 'http-status/extra/cloudflare';
// console.log('Cloudflare 522 Message:', cloudflareStatus[522_MESSAGE]);

view raw JSON →