{"id":16375,"library":"http-codes","title":"HTTP Status Code Map","description":"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`.","status":"abandoned","version":"1.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/flesler/node-http-codes","tags":["javascript","http","status","codes","messages","builtin","map","nodejs"],"install":[{"cmd":"npm install http-codes","lang":"bash","label":"npm"},{"cmd":"yarn add http-codes","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-codes","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is a CommonJS module and directly exports the status code map object. Modern ESM imports will fail without a CJS interoperability layer.","wrong":"import httpCodes from 'http-codes';","symbol":"httpCodes","correct":"const httpCodes = require('http-codes');"},{"note":"While the map contains properties like `OK`, direct destructuring requires CommonJS `require()`. Named ESM imports are not supported.","wrong":"import { OK } from 'http-codes';","symbol":"OK","correct":"const { OK, NOT_FOUND } = require('http-codes');"}],"quickstart":{"code":"const httpCodes = require('http-codes');\n\nconsole.log('HTTP Status Codes Map:');\nconsole.log(httpCodes);\n\n// Access a specific status code\nconst okCode = httpCodes.OK;\nconsole.log(`\\nOK (200): ${okCode}`);\n\nconst notFoundCode = httpCodes.NOT_FOUND;\nconsole.log(`NOT_FOUND (404): ${notFoundCode}`);\n\nconst imATeapotCode = httpCodes.IM_A_TEAPOT;\nconsole.log(`IM_A_TEAPOT (418): ${imATeapotCode}`);\n\n// Example usage in a simple server (requires Node.js http module)\nconst http = require('http');\n\nconst server = http.createServer((req, res) => {\n  if (req.url === '/success') {\n    res.writeHead(httpCodes.OK, { 'Content-Type': 'text/plain' });\n    res.end('Request successful!');\n  } else if (req.url === '/not-found') {\n    res.writeHead(httpCodes.NOT_FOUND, { 'Content-Type': 'text/plain' });\n    res.end('Resource not found.');\n  } else {\n    res.writeHead(httpCodes.IM_A_TEAPOT, { 'Content-Type': 'text/plain' });\n    res.end('I\\u0027m a teapot.');\n  }\n});\n\nserver.listen(3000, () => {\n  console.log('\\nServer listening on http://localhost:3000');\n  console.log('Try visiting /success, /not-found, or any other path.');\n});","lang":"javascript","description":"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."},"warnings":[{"fix":"For modern applications, consider using actively maintained alternatives like `http-status-codes` or `http-status`. If forced to use, ensure your environment supports CommonJS `require()` and consider a bundler to handle compatibility.","message":"This package is extremely old, published in 2014, and specifically based on Node.js 0.10.22. It is not compatible with modern JavaScript module systems (ESM) without explicit CommonJS interop.","severity":"breaking","affected_versions":"1.0.0"},{"fix":"Always verify if a specific HTTP code is present. For up-to-date and complete HTTP status code lists, use current libraries like `http-status-codes` which are actively maintained and incorporate RFC updates.","message":"The package does not contain newer HTTP status codes defined after 2014 (e.g., 421 Misdirected Request, 425 Too Early, 451 Unavailable For Legal Reasons, 103 Early Hints). Relying on this package for a comprehensive list of modern codes will lead to omissions.","severity":"gotcha","affected_versions":"1.0.0"},{"fix":"If message retrieval or reverse lookups are needed, you will need to implement that logic yourself or switch to a more feature-rich library.","message":"The package exports a plain object directly. There are no functions to get status messages from codes, or to parse messages, which are common features in more modern HTTP status code libraries.","severity":"gotcha","affected_versions":"1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Use CommonJS `require()` syntax: `const { OK } = require('http-codes');` or `const httpCodes = require('http-codes'); const okCode = httpCodes.OK;`","cause":"Attempting to use ES module named import syntax (`import { OK } from 'http-codes';`) with a CommonJS-only package.","error":"SyntaxError: Named export 'OK' not found. The requested module 'http-codes' does not provide an export named 'OK'"},{"fix":"While `http-codes` *is* CJS, this error often appears when attempting to use CJS-only packages in an ESM project without proper configuration. For `http-codes`, ensure your project context is CJS, or if ESM, use dynamic `import()`: `const httpCodes = await import('http-codes');` (though direct object access might need `httpCodes.default` depending on interop). Better yet, use a modern alternative.","cause":"Attempting to `require()` a package in an ESM context that does not provide a CommonJS entry point or is explicitly ESM-only. (This package is CJS, but this error is common for developers trying to 'require' in ESM projects)","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported."}],"ecosystem":"npm"}