HTTP Status Codes Map

3.0.0 · active · verified Tue Apr 21

This package, `builtin-status-codes`, provides a direct mapping of HTTP status codes to their corresponding human-readable messages. It retrieves the latest standard codes directly from Node.js's built-in `http` module when running in a Node.js environment, ensuring accuracy and up-to-date information without external dependencies. For browser environments, it offers a pre-built, zero-dependency version, making it suitable for universal JavaScript applications. The current stable version is 3.0.0. Due to its direct sourcing from Node's core and the stable nature of HTTP status codes, its release cadence is typically infrequent, primarily updating when Node.js introduces new codes or when there are build tool chain updates. Its key differentiator is providing a consistent, minimal API for both Node.js and browser contexts, leveraging built-in capabilities where possible.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing the status codes map, retrieving messages for specific numeric codes, and iterating through all available codes.

import codes from 'builtin-status-codes';

// Get the message for a specific status code
const okMessage = codes[200];
console.log(`200: ${okMessage}`); // Output: 200: OK

const notFoundMessage = codes[404];
console.log(`404: ${notFoundMessage}`); // Output: 404: Not Found

const serverErrorMessage = codes[500];
console.log(`500: ${serverErrorMessage}`); // Output: 500: Internal Server Error

// Iterate over all known status codes and messages
console.log('\nAll available status codes:');
for (const codeStr in codes) {
  const code = Number(codeStr);
  // Filter out any non-numeric or inherited properties
  if (Number.isInteger(code) && code > 0) {
    console.log(`${code}: ${codes[code]}`);
  }
}

view raw JSON →