CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-http-status

Utility to interact with HTTP status codes

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

HTTP Status

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.

Package Information

  • Package Name: http-status
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install http-status

Core Imports

import 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.

Basic Usage

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"

Architecture

HTTP Status is organized around several key components:

  • Main Status Object: Complete collection of all standard HTTP status codes with multiple access patterns
  • Status Classes: Classification system grouping status codes by first digit (1xx-5xx)
  • Extra Status Codes: Additional codes from popular web servers (NGINX, IIS, Cloudflare) and unofficial codes
  • Specialty Modules: Pre-merged modules combining standard codes with specific server codes
  • TypeScript Integration: Full type definitions for all status objects and access patterns

Capabilities

Standard HTTP Status Codes

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;
}

Standard Status Codes

Status Code Classes

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;
}

Status Classes

Extra Status Codes

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;
}

Extra Status Codes

Specialty Modules

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";

Specialty Modules

Types

// 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;
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/http-status@2.1.x
Publish Source
CLI
Badge
tessl/npm-http-status badge