{"id":13625473,"url":"https://github.com/adaltas/node-http-status","last_synced_at":"2025-05-14T01:11:33.712Z","repository":{"id":508925,"uuid":"1527743","full_name":"adaltas/node-http-status","owner":"adaltas","description":"Utility to interact with HTTP status code in Node.js","archived":false,"fork":false,"pushed_at":"2025-02-04T19:45:56.000Z","size":340,"stargazers_count":476,"open_issues_count":3,"forks_count":59,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-10T16:59:29.083Z","etag":null,"topics":["http-status-code","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adaltas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-03-25T23:34:47.000Z","updated_at":"2025-04-07T02:22:14.000Z","dependencies_parsed_at":"2023-02-12T00:45:51.901Z","dependency_job_id":"bc865546-4650-4e00-917c-86e4bf958312","html_url":"https://github.com/adaltas/node-http-status","commit_stats":{"total_commits":198,"total_committers":26,"mean_commits":7.615384615384615,"dds":"0.20707070707070707","last_synced_commit":"13417aaa5d95aafbd96aedfc86b4d7b1cc963860"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adaltas%2Fnode-http-status","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adaltas%2Fnode-http-status/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adaltas%2Fnode-http-status/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adaltas%2Fnode-http-status/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adaltas","download_url":"https://codeload.github.com/adaltas/node-http-status/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254049446,"owners_count":22006061,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http-status-code","nodejs"],"created_at":"2024-08-01T21:01:56.387Z","updated_at":"2025-05-14T01:11:28.703Z","avatar_url":"https://github.com/adaltas.png","language":"TypeScript","readme":"# HTTP Status codes for Node.js\n\nUtility to interact with HTTP status codes.\n\n## Migration to v2.x\n\nVersion 2 is a migration of the library to ESM modules and TypeScript. The API remains the same. The build system generates both ESM and CommonJS exports.\n\nFor ESM users, the import remains the same.\n\n```js\nimport status from \"http-status\";\n// Or\nimport { status } from \"http-status\";\n```\n\nFor CommonJs users, update the `require` statement.\n\n```js\nconst { status } = require(\"http-status\");\n// Or\nconst { default: status } = require(\"http-status\");\n```\n\n## Usage\n\nOnce you import or require this module, you may call it with either an HTTP code or a status name. With an HTTP code, you will get the status name while with a status name you will get an HTTP code or some complementary information.\n\nFor example, the following will return \\\n`status[418]` --\u003e `\"I'm a teapot\"` \\\n`status[\"418_NAME\"]` --\u003e `\"IM_A_TEAPOT\"` \\\n`status[\"418_MESSAGE\"]` --\u003e `\"Any attempt to brew coffee with a teapot should result in the error code \"418 I'm a teapot\". The resulting entity body MAY be short and stout.\"` . \\\n`status[\"418_CLASS\"]` --\u003e `\"4xx\"` \\\n`status.IM_A_TEAPOT` --\u003e `418`\n\nThe package is written in TypeScript and built for CommonJS and ESM.\n\n## HTTP Status codes\n\nHTTP code names, information, and classes are respectively accessible with the property `{code}_NAME`, `{code}_MESSAGE` and `{code}_CLASS`. This includes all statuses in the [IANA HTTP Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml), with the only addition being `418 I'm a teapot`.\n\n## Extra codes\n\nExtra status code are also made available that are not defined in the IANA registry, but used by popular softwares. They are grouped by category. Specific properties are exported by `http-status` under the property `extra` followed by the category name. Also, extra codes are merge with regular status codes and made available as modules available inside `http-status/lib/{category}`.\n\nAvailable categories are:\n\n\u003cdl\u003e\n  \u003cdt\u003e\u003ccode\u003eunofficial\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eThis represent a list of codes which are not specified by any standard.\u003c/dd\u003e\n  \u003cdt\u003e\u003ccode\u003eiis\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eMicrosoft's Internet Information Services (IIS) web server expands the 4xx error class to signal errors with the client's request.\u003c/dd\u003e\n  \u003cdt\u003e\u003ccode\u003enginx\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eThe NGINX web server software expands the 4xx error class to signal issues with the client's request.\u003c/dd\u003e\n  \u003cdt\u003e\u003ccode\u003ecloudflare\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eCloudflare's reverse proxy service expands the 5xx error class to signal issues with the origin server.\u003c/dd\u003e\n\u003c/dl\u003e\n\nThey are accessible throught the `status.extra[category]` property. It is also possible to import one of the category with `import status from \"http-status/\u003ccategory\u003e\" or `const status = require(\"http-status/\u003ccategory\u003e\")`. In the later case, all the categories properties are merge with the common HTTP statuses.\n\n## HTTP Status code classes\n\nIn addition to HTTP status codes, this module also contains status code classes under the `classes` property. Similar to HTTP codes, you can access class names and messages with the property `{class}_NAME` and `{class}_MESSAGE`.\n\n## API organization\n\nThe API is structured as follows:\n\n```\n100\n100_NAME\n100_MESSAGE\n100_CLASS\nCONTINUE\n101\n101_NAME\n101_MESSAGE\n101_CLASS\nSWITCHING_PROTOCOLS\n…\nclasses.\n├── 1xx\n├── 1xx_NAME\n├── 1xx_MESSAGE\n├── INFORMATIONAL\n├── 2xx\n├── 2xx_NAME\n├── 2xx_MESSAGE\n├── SUCCESSFUL\n├── …\nextra.\n├── unofficial.\n│   ├── 103\n│   ├── 103_NAME\n│   ├── 103_MESSAGE\n│   ├── 103_CLASS\n│   ├── CHECKPOINT\n│   ├── …\n├── iis.\n│   ├── 440\n│   ├── 440_NAME\n│   ├── 440_MESSAGE\n│   ├── 440_CLASS\n│   ├── LOGIN_TIME_OUT\n│   ├── …\n├── nginx.\n│   ├── 444\n│   ├── 444_NAME\n│   ├── 444_MESSAGE\n│   ├── 444_CLASS\n│   ├── NO_RESPONSE\n│   ├── …\n├── cloudflare.\n│   ├── 520\n│   ├── 520_NAME\n│   ├── 520_MESSAGE\n│   ├── 520_CLASS\n│   ├── UNKNOWN_ERROR\n│   ├── …\n```\n\nFor additional information, please refer to [original code](./src/index.ts).\n\n## Example API usage\n\nThe [api example](./samples/api.js) illustrate how to access status names by code and number and how to extra various associated informations.\n\n```javascript\nimport status from \"http-status\";\n\nconsole.info(status.INTERNAL_SERVER_ERROR);\n// Output: 500\n\nconsole.info(status[500]);\nconsole.info(status[status.INTERNAL_SERVER_ERROR]);\n// Both output: \"Internal Server Error\"\n\nconsole.info(status[\"500_NAME\"]);\nconsole.info(status[`${status.INTERNAL_SERVER_ERROR}_NAME`]);\n// Both output: \"INTERNAL_SERVER_ERROR\"\n\nconsole.info(status[\"500_MESSAGE\"]);\nconsole.info(status[`${status.INTERNAL_SERVER_ERROR}_MESSAGE`]);\n// Both output: \"A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.\"\n\nconsole.info(status[\"500_CLASS\"]);\nconsole.info(status[`${status.INTERNAL_SERVER_ERROR}_CLASS`]);\n// Both output: \"5xx\"\n```\n\n## Example using `classes`\n\n```javascript\nimport status from \"http-status\";\n\nconst responseCode = status.INTERNAL_SERVER_ERROR;\n\nswitch (status[`${responseCode}_CLASS`]) {\n  case status.classes.INFORMATIONAL:\n    // The responseCode is 1xx\n    break;\n  case status.classes.SUCCESSFUL:\n    // The responseCode is 2xx\n    break;\n  case status.classes.REDIRECTION:\n    // The responseCode is 3xx\n    break;\n  case status.classes.CLIENT_ERROR:\n    // The responseCode is 4xx\n    break;\n  case status.classes.SERVER_ERROR:\n    // The responseCode is 5xx\n    break;\n\n  default:\n    // Unknown\n    break;\n}\n```\n\n## Example using the `extra` property\n\n```javascript\n// Accessing property from the NGINX category\nimport status from \"http-status\";\nconsole.info(status.extra.nginx.NO_RESPONSE);\n\n// Accessing default HTTP status merged with NGINX status\nimport status from \"http-status/lib/nginx\";\nconsole.info(status.IM_A_TEAPOT);\nconsole.info(status.NO_RESPONSE);\n```\n\n## Example integrating Express\n\nThe [express example](./samples/express.js) integrate the library with a real wold usage.\n\n```javascript\nimport express from \"express\";\nimport redis from \"redis\";\nimport status from \"http-status\";\n\n// New Express HTTP server\nconst app = express.createServer();\n// Regster a route\napp.get(\"/\", (req, res) =\u003e {\n  const client = redis.createClient();\n  client.ping((err, msg) =\u003e {\n    if (err) {\n      return res.send(status.INTERNAL_SERVER_ERROR);\n    }\n    res.send(msg, status.OK);\n  });\n});\n// Start the HTTP server\napp.listen(3000);\n```\n\n## Contributors\n\n- David Worms: \u003chttps://github.com/wdavidw\u003e\n- Daniel Gasienica: \u003chttps://github.com/gasi\u003e\n- Rodrigo: \u003crfsbraz@gmail.com\u003e\n- Paul Vollmer: \u003cpaul.vollmer@fh-potsdam.de\u003e\n- James Barcellano: \u003chttps://github.com/ckeboss\u003e\n\nThe project is sponsored by [Adaltas](https://www.adaltas.com) based in Paris, France. Adaltas offers support and consulting on distributed systems, big data and open source.\n\n## Developers\n\nTo automatically generate a new version:\n\n```bash\nnpm run release\n```\n\nPackage publication is handled by the CI/CD with GitHub action.\n","funding_links":[],"categories":["nodejs"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadaltas%2Fnode-http-status","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadaltas%2Fnode-http-status","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadaltas%2Fnode-http-status/lists"}