HTTP Status provides a comprehensive utility library for interacting with HTTP status codes in Node.js applications. It offers both human-readable names and numeric codes for all standard HTTP status codes defined in the IANA HTTP Status Code Registry, plus the popular 418 'I'm a teapot' code. The library supports accessing status information through multiple patterns and includes extra status codes from popular web servers.
npm install http-statusimport status from "http-status";
import { status } from "http-status";
import type { HttpStatus } from "http-status";For CommonJS:
const { status } = require("http-status");
const { default: status } = require("http-status");Note: The package supports both ESM and CommonJS through dual exports defined in package.json. All import patterns are supported through the configured export paths.
import status from "http-status";
// Get status name from code
console.log(status[200]); // "OK"
console.log(status[404]); // "Not Found"
// Get status code from constant
console.log(status.OK); // 200
console.log(status.NOT_FOUND); // 404
// Get detailed information
console.log(status["200_NAME"]); // "OK"
console.log(status["200_MESSAGE"]); // "Standard response for successful HTTP requests."
console.log(status["200_CLASS"]); // "2xx"
// Work with status classes
console.log(status.classes.SUCCESSFUL); // "2xx"
console.log(status.classes["2xx"]); // "Successful"
// Access extra status codes
console.log(status.extra.nginx.NO_RESPONSE); // 444
console.log(status.extra.cloudflare[520]); // "Unknown Error"HTTP Status is organized around several key components:
Core HTTP status codes (1xx-5xx) with multiple access patterns including numeric lookup, constant names, and detailed information.
interface StatusObject {
// Numeric keys return status names
[code: number]: string;
// Named constants return status codes
[name: string]: number | string;
// Information accessors
[key: `${number}_NAME`]: string;
[key: `${number}_MESSAGE`]: string;
[key: `${number}_CLASS`]: string;
}Classification system that groups status codes by their first digit, providing semantic meaning and class information.
interface StatusClasses {
// Class identifiers
"1xx": "Informational";
"2xx": "Successful";
"3xx": "Redirection";
"4xx": "Client Error";
"5xx": "Server Error";
// Named constants
INFORMATIONAL: "1xx";
SUCCESSFUL: "2xx";
REDIRECTION: "3xx";
CLIENT_ERROR: "4xx";
SERVER_ERROR: "5xx";
// Class names and messages
[key: `${string}xx_NAME`]: string;
[key: `${string}xx_MESSAGE`]: string;
}Additional status codes from popular web servers and unofficial codes that extend the standard HTTP status code set.
interface ExtraStatusCodes {
unofficial: StatusObject;
iis: StatusObject;
nginx: StatusObject;
cloudflare: StatusObject;
}Pre-configured modules that merge standard status codes with specific server status codes for convenience.
// Available specialty imports
import status from "http-status/cloudflare";
import status from "http-status/nginx";
import status from "http-status/iis";
import status from "http-status/unofficial";// Main status object type
type HttpStatus = typeof status;
// Status classes type
type HttpStatusClasses = typeof status.classes;
// Extra status code types
type HttpStatusUnofficial = typeof status.extra.unofficial;
type HttpStatusIis = typeof status.extra.iis;
type HttpStatusNginx = typeof status.extra.nginx;
type HttpStatusCloudflare = typeof status.extra.cloudflare;