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`.
npm install http-codesVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
If message retrieval or reverse lookups are needed, you will need to implement that logic yourself or switch to a more feature-rich library.
Use CommonJS `require()` syntax: `const { OK } = require('http-codes');` or `const httpCodes = require('http-codes'); const okCode = httpCodes.OK;`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.No dependency data recorded yet.