{"id":15284297,"url":"https://github.com/shawshankkumar/express-status-validation","last_synced_at":"2026-01-22T12:54:24.134Z","repository":{"id":168173796,"uuid":"643261864","full_name":"shawshankkumar/express-status-validation","owner":"shawshankkumar","description":"A dead simple npm library to validate status codes in express.js","archived":false,"fork":false,"pushed_at":"2023-09-14T19:41:57.000Z","size":196,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T17:21:25.219Z","etag":null,"topics":["express","http","middleware"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/express-status-validate","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shawshankkumar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"Contributing.md","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":"2023-05-20T15:51:37.000Z","updated_at":"2024-06-24T16:19:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"62f5cf65-36ed-4d3f-b8c2-9a7ba1c1657c","html_url":"https://github.com/shawshankkumar/express-status-validation","commit_stats":null,"previous_names":["shawshankkumar/express-status-validation"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shawshankkumar%2Fexpress-status-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shawshankkumar%2Fexpress-status-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shawshankkumar%2Fexpress-status-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shawshankkumar%2Fexpress-status-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shawshankkumar","download_url":"https://codeload.github.com/shawshankkumar/express-status-validation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248644183,"owners_count":21138565,"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":["express","http","middleware"],"created_at":"2024-09-30T14:53:11.994Z","updated_at":"2026-01-22T12:54:19.096Z","avatar_url":"https://github.com/shawshankkumar.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/express-status-validate.svg\" alt=\"author shawshankkumar\"/\u003e\n    \u003cimg src=\"https://img.shields.io/badge/author-shawshankkumar-orange\" alt=\"author shawshankkumar\"/\u003e\n    \u003cimg src=\"https://img.shields.io/npm/l/express-status-validate.svg\" alt=\"author shawshankkumar\"/\u003e\n\u003c/div\u003e\n\u003cbr/\u003e\n\u003cp align=\"center\"\u003e\n    A dead simple npm library to validate express.js response status codes.\n\u003c/p\u003e\n\n## Inspiration for this package!\n\n1. To learn how to make packages 😉\n2. I spent around 40-50 minutes debugging why [SRMKZILLA's](https://srmkzilla.net) backend kept crashing. Found out someone passed the mongo error codes(single digit) to express and viola.\n3. After months of making this, bun 1.0.0 was released and I thought, Hey, why not migrate everything in this project to bun (test, runtime, package management and more) and added a bunch of actions.\n\n## What does it do?\n\nIt does what a middleware should, it sits quietly and on a day to day basis, you never notice it. Express is great, but it can be better. In TypeScript, passing a wrong status code is not that easy. But in JavaScript? One could pass a tank and the code would run (Thanks JS :) ). This package safeguards your app from throwing unwanted errors or crashing. What can you pass?\n\n1. If you pass a valid status code like 200, it works. It doesn't change anything in the original status code.\n2. BUT, if you pass \"200\" or \"200OK\", it converts it to 200 and sends it. But what if you pass something like 799 (invalid status code)? In that case a default status code is set and sent.\n3. And you guesses correct, you can easily set the default status code you want.\n\n## How to use it in your JS/TS project?\n\nCheckout this [replit example](https://replit.com/@ShashankKumar12/express-status-validate?v=1#index.js)\n\nOR follow the steps below:\n\n1. CD into the root folder of your project!\n2. Install [express-status-validate](https://www.npmjs.com/package/express-status-validate) using pnpm (pnpm is cool, yarn is boring and npm is npm.)\n\n```\npnpm i express-status-validate\n```\n\nor\n\n```\nnpm i express-status-validate\n```\n\nor\n\n```\nyarn add express-status-validate\n```\n\n3. Open the entry point of your express app.\n\nOur express application before adding the package:\n\n```\nconst express = require(\"express\");\n\nconst app = express();\n\napp.get(\"/healthcheck\", (req, res) =\u003e {\n  //This should throw an error and crash.\n  res.status(200123).send(\"OK\");\n});\n\napp.listen(3000, () =\u003e {\n  console.log(\"Server started on port 3000\");\n});\n\n```\n\nAfter adding the [express-status-validate](https://www.npmjs.com/package/express-status-validate) :\n\n```\nconst express = require(\"express\");\nconst expressStatusValidate = require(\"express-status-validate\");\n\nconst app = express();\n\n// 500 is optional, you can pass any valid http status code\napp.use(expressStatusValidate(500));\n\napp.get(\"/healthcheck\", (req, res) =\u003e {\n  //This should throw an error and crash an application but it doesn't anymore.\n  res.status(200123).send(\"OK\");\n});\n\napp.listen(3000, () =\u003e {\n  console.log(\"Server started on port 3000\");\n});\n\n```\n\n\u003e **_NOTE:_** app.use(expressStatusValidate(500)) must be on top to work as desired.\n\n## Examples:\n\nWe are in the process of adding more examples and testing this library to make sure it works smoothly everywhere. Currently we have the following examples (Shoutout to [Harshit Singh, my roommate :p](https://github.com/whiletrueee) for being the first user of this library) :\n\n1. [JavaScript Example](https://github.com/shawshankkumar/express-status-validation/tree/main/example/js-example)\n2. [TypeScript Example](https://github.com/shawshankkumar/express-status-validation/tree/main/example/ts-example)\n\n## License 📜\n\n`express-status-validate` is available under the ISC license. See the LICENSE file for more info.\n\n## Contributing 🤝\n\nPlease read `Contributing.md` for details on our code of conduct, and the process for submitting pull requests to us.\n\n## How to contribute to this project:\n\n1. Fork it 😜 and make sure you have Node(\u003e14) installed!\n2. Install the pnpm using\n\n```\nnpm i -g pnpm\n```\n\n3. Install the dependencies\n\n```\ncd package \u0026\u0026 pnpm i\n```\n\n4. Do you magic (We recommend that you stick to the code and not configuration files unless there is a specific reason to do so)🪄\n5. Build the TypeScript\n\n```\npnpm run build\n```\n\n6. Run npm link and move to the examples and run npm link \u003cpackage-name\u003e and test it! [Refer to this!](https://www.jamesqquick.com/blog/how-to-test-npm-packages-locally/)\n7. Make sure you run all the tests before making a pull request!\n8. Make a pull request, sit back and enjoy while we review your changes.\n\n## Forking this repo 🚨\n\nMany people have contacted us asking if they can use this code for their own websites. The answer to that question is usually \"yes\", with attribution. There are some cases, such as using this code for a business or something that is greater than a personal project, that we may be less comfortable saying yes to. If in doubt, please don't hesitate to ask us.\n\nWe value keeping this site open source, but as you all know, _**plagiarism is bad**_. We spent a non-negligible amount of effort developing, designing, and trying to perfect this iteration of our website, and we are proud of it! All we ask is to not claim this effort as your own.\n\nSo, feel free to fork this repo. If you do, please just give us proper credit by linking back to this repo. Refer to this handy [quora post](https://www.quora.com/Is-it-bad-to-copy-other-peoples-code) if you're not sure what to do. Thanks!\n\n## Example without express-status-validate:\n\n\u003cimg width=\"1331\" alt=\"image\" src=\"https://github.com/shawshankkumar/express-status-validation/assets/74819565/fbe47e15-2080-4b24-bcd7-e7cee62c6448\"\u003e\n\n## Example with express-status-validate enabled:\n\n\u003cimg width=\"1327\" alt=\"image\" src=\"https://github.com/shawshankkumar/express-status-validation/assets/74819565/21626ea0-9d24-49cc-8d1d-78797e92f961\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshawshankkumar%2Fexpress-status-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshawshankkumar%2Fexpress-status-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshawshankkumar%2Fexpress-status-validation/lists"}