HTTP Status Code Map

1.0.0 · abandoned · verified Wed Apr 22

This `http-codes` package provides a straightforward JavaScript object that maps common HTTP status message constants (e.g., `OK`, `NOT_FOUND`) to their corresponding numeric codes (e.g., `200`, `404`). Originally released as version `1.0.0` in 2014, it explicitly based its mapping on the built-in HTTP status codes available in Node.js `0.10.22`. The package emphasizes simplicity and a lack of external dependencies, aiming to automatically incorporate updates from Node.js's internal HTTP module, although it has not received any updates since its initial release. Due to its age and lack of maintenance, it does not include many modern HTTP status codes and is primarily suitable for legacy Node.js environments or projects that specifically require the exact mapping from Node.js `0.10.22`.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to `require` the `http-codes` map and access specific status codes. It also shows a basic Node.js HTTP server using these codes to set response statuses.

const httpCodes = require('http-codes');

console.log('HTTP Status Codes Map:');
console.log(httpCodes);

// Access a specific status code
const okCode = httpCodes.OK;
console.log(`\nOK (200): ${okCode}`);

const notFoundCode = httpCodes.NOT_FOUND;
console.log(`NOT_FOUND (404): ${notFoundCode}`);

const imATeapotCode = httpCodes.IM_A_TEAPOT;
console.log(`IM_A_TEAPOT (418): ${imATeapotCode}`);

// Example usage in a simple server (requires Node.js http module)
const http = require('http');

const server = http.createServer((req, res) => {
  if (req.url === '/success') {
    res.writeHead(httpCodes.OK, { 'Content-Type': 'text/plain' });
    res.end('Request successful!');
  } else if (req.url === '/not-found') {
    res.writeHead(httpCodes.NOT_FOUND, { 'Content-Type': 'text/plain' });
    res.end('Resource not found.');
  } else {
    res.writeHead(httpCodes.IM_A_TEAPOT, { 'Content-Type': 'text/plain' });
    res.end('I\u0027m a teapot.');
  }
});

server.listen(3000, () => {
  console.log('\nServer listening on http://localhost:3000');
  console.log('Try visiting /success, /not-found, or any other path.');
});

view raw JSON →