{"id":23274148,"url":"https://github.com/buzut/node-body-validator","last_synced_at":"2025-08-21T06:31:40.717Z","repository":{"id":34924228,"uuid":"191368527","full_name":"Buzut/node-body-validator","owner":"Buzut","description":"Powerful promise based validator module to efficiently validate node body params","archived":false,"fork":false,"pushed_at":"2022-10-07T07:34:10.000Z","size":148,"stargazers_count":0,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-09T03:36:31.611Z","etag":null,"topics":["json","json-api","nodejs","validation-library"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Buzut.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-11T12:37:19.000Z","updated_at":"2021-03-04T09:28:19.000Z","dependencies_parsed_at":"2023-01-15T10:32:35.455Z","dependency_job_id":null,"html_url":"https://github.com/Buzut/node-body-validator","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Buzut%2Fnode-body-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Buzut%2Fnode-body-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Buzut%2Fnode-body-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Buzut%2Fnode-body-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Buzut","download_url":"https://codeload.github.com/Buzut/node-body-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230494926,"owners_count":18235047,"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":["json","json-api","nodejs","validation-library"],"created_at":"2024-12-19T20:12:21.114Z","updated_at":"2024-12-19T20:12:21.873Z","avatar_url":"https://github.com/Buzut.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node body validator\nMakes parameters validation in Node.js a breeze. With promise chaining, you validate incoming requests straight away, data flows between controllers and models and errored requests are efficiently handled.\n\nAs an exemple, let's validate a login request.\n\n```js\n// /controllers/userController\n\nconst RequestValidator = require('node-body-validator');\nconst handleError = require('../lib/handleError');\nconst userModel = require('../models/userModel');\n\nconst reqValidator = new RequestValidator('form');\n\nexports.register = function (req, res) {\n    reqValidator.validate(req, [\n        { name: 'email', type: 'string', validator: v =\u003e v.pattern(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,6}$/i), failMsg: 'email must be an email string' },\n        { name: 'password', type: 'string', validator: v =\u003e v.minLength(8).maxLength(50), failMsg: 'password must be comprised between 8 and 50 chars' }\n    ])\n    then(\n        post =\u003e userModel.create(post.email, post.password)\n        .then(([id, token]) =\u003e res.status(201).json({ id, token }));\n    )\n    .catch(err =\u003e handleError(err, res));\n};\n```\n\nSimple, expressive and beautifully powerful, right? Data flows thoughout your app.\n\nConvinced? Let's explore all the possibilities in the next section.\n\n## Installation \u0026 usage\nThe module requires at least Node V6, appart from this, its install procedure is boringly conventional.\n\n```js\nnpm install --save node-body-validator\n```\n\nThis validator is the pure Node.js version of the [express-body-validator](https://github.com/Buzut/express-body-validator). The only difference between the them is that node-body-validator handles raw `request` object whereas with Express.js, `bodyParser` has taken care of the parsing.\n\nHence, this validator takes two parameters on instanciation:\n* `contentType` that can be either `form` for `application/x-www-form-urlencoded` or `json` for `application/json` (you can also pass full value if you whish).\n* `maxBodySize` is the maximum authorized size of the body in bytes. It defaults to 1MB. Promise is rejected if request is bigger than that.\n\n```js\nconst RequestValidator = require('node-body-validator');\nconst reqValidator = new RequestValidator('json', 10e6); // JSON encoding with body up to 10MB\n```\n\nApart from that, the API is exactly the same as the other module. Check out the [docs there](https://github.com/Buzut/express-body-validator).\n\n## Contributing\nThere's sure room for improvement, so feel free to hack around and submit PRs!\nPlease just follow the style of the existing code, which is [Airbnb's style](http://airbnb.io/javascript/) with [minor modifications](.eslintrc).\n\nTo maintain things clear and visual, please follow the [git commit template](https://github.com/Buzut/git-emojis-hook).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuzut%2Fnode-body-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuzut%2Fnode-body-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuzut%2Fnode-body-validator/lists"}