{"id":22107479,"url":"https://github.com/nextyfine-dev/fastest-expressjs-validator","last_synced_at":"2026-04-29T06:36:35.337Z","repository":{"id":198586960,"uuid":"701105664","full_name":"nextyfine-dev/fastest-expressjs-validator","owner":"nextyfine-dev","description":"fastest-expressjs-validator is a robust and easy-to-use middleware package for Express.js applications that simplifies request validation. It leverages the power of the fastest-validator library to validate incoming requests efficiently.","archived":false,"fork":false,"pushed_at":"2023-12-16T17:48:55.000Z","size":125,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-28T12:20:04.880Z","etag":null,"topics":["express","expressjs","middleware","validator"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/fastest-expressjs-validator","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/nextyfine-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2023-10-05T23:44:13.000Z","updated_at":"2024-01-30T07:40:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"797fb959-3211-4d8e-a3b0-107a566170fb","html_url":"https://github.com/nextyfine-dev/fastest-expressjs-validator","commit_stats":null,"previous_names":["nextyfine-dev/fastest-express-validator"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nextyfine-dev/fastest-expressjs-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nextyfine-dev%2Ffastest-expressjs-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nextyfine-dev%2Ffastest-expressjs-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nextyfine-dev%2Ffastest-expressjs-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nextyfine-dev%2Ffastest-expressjs-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nextyfine-dev","download_url":"https://codeload.github.com/nextyfine-dev/fastest-expressjs-validator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nextyfine-dev%2Ffastest-expressjs-validator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262916636,"owners_count":23383886,"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","expressjs","middleware","validator"],"created_at":"2024-12-01T08:17:48.427Z","updated_at":"2026-04-29T06:36:30.318Z","avatar_url":"https://github.com/nextyfine-dev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastest-expressjs-validator 🚀\n\n🚀 Effortless Request Validation for [Express.js](https://github.com/expressjs/express)\n\n- [fastest-expressjs-validator 🚀](#fastest-expressjs-validator-)\n  - [Description](#description)\n  - [Features](#features)\n  - [Installation](#installation)\n    - [Using bun:](#using-bun)\n    - [Using npm:](#using-npm)\n    - [Using yarn:](#using-yarn)\n  - [Functions and Arguments](#functions-and-arguments)\n    - [`validateRequest`](#validaterequest)\n  - [Request Validation Options](#request-validation-options)\n    - [Query Validation](#query-validation)\n    - [Params Validation](#params-validation)\n    - [Body Validation](#body-validation)\n    - [Headers Validation](#headers-validation)\n    - [`validateMultiRequest`](#validatemultirequest)\n  - [Usage](#usage)\n    - [Importing the package](#importing-the-package)\n    - [Middleware for Single Request Type](#middleware-for-single-request-type)\n    - [Middleware for Multiple Request Types](#middleware-for-multiple-request-types)\n  - [More code examples](#more-code-examples)\n  - [See More About Schemas and All Details](#see-more-about-schemas-and-all-details)\n  - [License](#license)\n\n## Description\n\n`fastest-expressjs-validator` simplifies request validation in Express.js applications. Define schemas for request bodies, URL parameters, and query parameters with ease. Improve the reliability and security of your Express API effortlessly. It leverages the power of the [`fastest-validator`](https://www.npmjs.com/package/fastest-validator) library to validate incoming requests efficiently.\n\n## Features\n\n✅ Define validation schemas for body, params, and queries.\n\n✅ Enhanced security and reliability for your Express API.\n\n✅ Customizable validation options.\n\n✅ Support for asynchronous and synchronous validation.\n\n✅ Detailed error messages and structured responses for validation errors.\n\n✅ High performance with minimal code usage.\n\n✅ Written in TypeScript for enhanced type safety and developer experience.\n\n## Installation\n\nYou can install `fastest-expressjs-validator` using bun or npm or yarn:\n\n### Using bun:\n\n```bash\nbun add fastest-expressjs-validator\n```\n\n### Using npm:\n\n```bash\nnpm install fastest-expressjs-validator\n```\n\n### Using yarn:\n\n```bash\nyarn add fastest-expressjs-validator\n```\n\n## Functions and Arguments\n\n### `validateRequest`\n\nA middleware function for request validation in Express.js.\n\n- **Arguments:**\n  - `schema: SchemaType`: The validation schema for the request.\n  - `validateOptions: ValidateOptions = body`\n    The type of request (\"body\", \"params\", \"query\", \"headers\") to validate (default is \"body\").\n  - `validatorOptions: ValidatorOptions = { haltOnFirstError: true }`: Custom validation options (default options include halting on the first error).\n\n## Request Validation Options\n\nWhen using this middleware, you have the flexibility to specify the type of request you want to validate (e.g., \"body,\" \"params,\" \"query,\" or \"headers\"). Here are the objects for `validateOptions`:\n\n### Query Validation\n\n```javascript\nconst query = {\n  requestType: \"query\",\n  multiRequest: false,\n};\n```\n\n### Params Validation\n\n```javascript\nconst params = {\n  requestType: \"params\",\n  multiRequest: false,\n};\n```\n\n### Body Validation\n\n```javascript\nconst body = {\n  requestType: \"body\",\n  multiRequest: false,\n};\n```\n\n### Headers Validation\n\n```javascript\nconst headers = {\n  requestType: \"headers\",\n  multiRequest: false,\n};\n```\n\n### `validateMultiRequest`\n\nA utility function for validating multiple request types.\n\n- **Arguments:**\n  - `schema: SchemaType`: The validation schema for the request.\n  - `validateOptions`: is not required! Automatically detects default options.\n  - `validatorOptions: ValidatorOptions = {}`: Custom validation options.\n\n```typescript\ntype SchemaType = ValidationSchema | MultiValidationSchema;\n```\n\n## Usage\n\n### Importing the package\n\n```typescript\nconst {\n  validateRequest,\n  validateMultiRequest,\n  query,\n} = require(\"fastest-expressjs-validator\");\n// or\nimport {\n  validateRequest,\n  validateMultiRequest,\n  query,\n} from \"fastest-expressjs-validator\";\n```\n\n### Middleware for Single Request Type\n\n```typescript\n// Define a validation schema\nconst schema = {\n  username: \"string\",\n  password: \"string\",\n};\n\n// Use the middleware in your Express route\napp.post(\"/login\", validateRequest(schema), (req, res) =\u003e {\n  // Your route logic here\n});\n\nOR;\n\nconst qSchema = {\n  q: \"string\",\n};\n\nconst validateQuery = validateRequest(qSchema, query);\n\napp.get(\"/\", validateQuery, (req, res) =\u003e {\n  // ... your code here\n});\n```\n\n### Middleware for Multiple Request Types\n\n```typescript\n// Define a validation schema\nconst multiSchema = {\n  body: {\n    username: \"string\",\n    password: \"string\",\n  },\n  params: {\n    id: \"number\",\n  },\n};\n\n// Use the middleware in your Express route\napp.put(\"/user/:id\", validateMultiRequest(multiSchema), (req, res) =\u003e {\n  // Your route logic here\n});\n```\n\n## More code examples\n\n`validationMiddleware.ts`\n\n```typescript\nimport {\n  MultiValidationSchema,\n  ValidationSchema,\n  validateMultiRequest,\n  validateRequest,\n  query,\n  params,\n} from \"fastest-expressjs-validator\";\n\nconst querySchema: ValidationSchema = {\n  name: \"string\",\n  $$strict: true,\n};\n\nconst bodySchema: ValidationSchema = {\n  userName: \"string\",\n  password: \"string\",\n  email: \"email\",\n  $$strict: true,\n};\n\nconst paramsSchema: ValidationSchema = {\n  id: \"string\",\n  $$strict: true,\n};\n\nconst multiSchema: MultiValidationSchema = {\n  body: {\n    userName: \"string\",\n    password: \"string\",\n    email: \"email\",\n    $$strict: true,\n  },\n  query: {\n    randomStr: \"string\",\n    $$strict: true,\n  },\n};\n\nconst headerParamSchema: MultiValidationSchema = {\n  headers: {\n    hasauth: \"string\",\n  },\n  params: {\n    id: \"string\",\n  },\n};\n\nexport const validateQuery = validateRequest(querySchema, query);\n\nexport const validateBody = validateRequest(bodySchema);\nexport const validateParams = validateRequest(paramsSchema, params);\n\nexport const validateMultiReq = validateMultiRequest(multiSchema);\n\nexport const validateHeaderParams = validateMultiRequest(headerParamSchema);\n```\n\n`app.ts`\n\n```typescript\nimport crypto from \"node:crypto\";\nimport express from \"express\";\nimport {\n  validateBody,\n  validateHeaderParams,\n  validateMultiReq,\n  validateParams,\n  validateQuery,\n} from \"./validationMiddleware\";\n\nconst app = express();\n\napp.disable(\"x-powered-by\");\napp.use(express.json());\napp.use(express.urlencoded({ extended: true }));\n\nconst hashPassword = (password: string) =\u003e {\n  const salt = crypto.randomBytes(16).toString(\"hex\");\n  return crypto.pbkdf2Sync(password, salt, 1000, 64, \"sha512\").toString(\"hex\");\n};\n\napp.get(\"/\", validateQuery, (req, res) =\u003e {\n  const { name } = req.query;\n  res.status(200).json({\n    message: `Validation working! From ${name}`,\n  });\n});\n\napp.post(\"/login\", validateBody, (req, res) =\u003e {\n  const { userName, password, email } = req.body;\n  const hashedPassword = hashPassword(password);\n  res.status(200).json({\n    userName,\n    email,\n    password: hashedPassword,\n  });\n});\n\napp.get(\"/getUser/:id\", validateParams, (req, res) =\u003e {\n  const { id } = req.params;\n  res.status(200).json({\n    message: `User found! : ${id}`,\n  });\n});\n\napp.post(\"/signup\", validateMultiReq, (req, res) =\u003e {\n  const { userName, password, email } = req.body;\n  const { randomStr } = req.query;\n  const hashedPassword = hashPassword(password);\n\n  res.status(201).json({\n    userName,\n    email,\n    randomStr,\n    password: hashedPassword,\n  });\n});\n\napp.post(\"/headers/:id\", validateHeaderParams, (req, res) =\u003e {\n  const { hasauth } = req.headers;\n  const { id } = req.params;\n  res.status(200).json({ hasauth, id });\n});\n\napp.listen(3001, () =\u003e\n  console.log(`App is listening on http://localhost:3001`)\n);\n```\n\n## See More About Schemas and All Details\n\nFor more details on [Documentation](https://github.com/icebob/fastest-validator/blob/master/README.md).\n\n## License\n\nThis package is open-source and available under the [MIT License](https://github.com/nextyfine-dev/fastest-express-validator/blob/main/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnextyfine-dev%2Ffastest-expressjs-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnextyfine-dev%2Ffastest-expressjs-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnextyfine-dev%2Ffastest-expressjs-validator/lists"}