{"library":"statuses","title":"HTTP Statuses Utility","type":"library","description":"The `statuses` package provides a comprehensive utility for working with HTTP status codes and messages in Node.js environments. It consolidates status information from official sources like the IANA Status Code Registry, as well as common implementations from the Node.js, NGINX, and Apache HTTP Server projects. Currently at stable version 2.0.2, the library maintains a steady release cadence focused on stability, minor updates, and continuous integration improvements rather than frequent feature additions, reflecting its role as a mature, low-level building block. Its key differentiator lies in its comprehensive data source aggregation and direct mapping capabilities, allowing developers to easily convert between numeric codes and descriptive messages, and access properties like whether a status indicates an empty body, a redirect, or a retryable condition. Unlike some HTTP utilities, `statuses` will throw an error for unknown codes or messages, ensuring strict adherence to recognized HTTP semantics.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install statuses"],"cli":null},"imports":["const status = require('statuses');","const status = require('statuses');\nconst allCodes = status.codes;","const status = require('statuses');\nconst msg = status.message[404];"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/jshttp/statuses","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/statuses","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"const status = require('statuses');\n\n// Get message from a numeric status code\nconsole.log('Status 403:', status(403));\nconsole.log('Status \"403\":', status('403'));\n\n// Get code from a status message (case-insensitive)\nconsole.log('Code for \"forbidden\":', status('forbidden'));\nconsole.log('Code for \"Not Found\":', status('Not Found'));\n\n// Access all known status codes\nconsole.log('All status codes (first 5):', status.codes.slice(0, 5));\n\n// Check if a status code expects an empty body\nconsole.log('Does 200 expect empty body?', !!status.empty[200]);\nconsole.log('Does 204 expect empty body?', !!status.empty[204]);\n\n// Check if a status code is a redirect\nconsole.log('Is 200 a redirect?', !!status.redirect[200]);\nconsole.log('Is 301 a redirect?', !!status.redirect[301]);\n\n// Get message directly from the message object\nconsole.log('Message for 404:', status.message[404]);\n\n// Error handling for unknown values\ntry {\n    status(306);\n} catch (e) {\n    console.error('Error for status(306):', e.message);\n}\n\ntry {\n    status('foo');\n} catch (e) {\n    console.error('Error for status(\"foo\"):', e.message);\n}","lang":"javascript","description":"Demonstrates core functionality including code-to-message and message-to-code lookups, accessing status code lists and properties like `empty` and `redirect`, and error handling for unknown values.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}