express-validator

A chainable Express middleware that wraps validator.js to validate and sanitize incoming request data with minimal boilerplate.

Library
npm
v7.3.2
6,235stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
82/100Excellent
Development Activity72
Maintenance76
Community80
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
85/100Excellent
Architecture78
Code Quality85
Innovation75
Learning Curve100

express-validator brings the extensive validator.js library of string validators and sanitizers into Express as a fluent, chainable middleware. Instead of hand-rolling if/else checks for every field in req.body, req.query, req.params, req.headers, or req.cookies, you attach a validation chain (e.g. check('email').isEmail().normalizeEmail()) directly to a route, and the library handles field selection — including nested paths and wildcards — validation, sanitization, and error collection for you.

Beyond individual field chains, it offers checkSchema() for declaring validations across many fields as a single object, oneOf() for alternative-field validation logic, and checkExact() to reject requests containing fields nobody validated. An ExpressValidator factory class lets teams register their own named validators and sanitizers with full TypeScript type inference, so custom rules read like built-in chain methods. The result is a mature, widely-used building block for input validation in Express APIs rather than a full framework or a one-off utility.

What You Get

  • Chainable per-field validation and sanitization via check(), body(), query(), param(), cookie(), and header()
  • A schema-based alternative, checkSchema(), for declaring validations across many fields in one object
  • oneOf() for requiring at least one of several alternative validation chains to pass
  • checkExact() to reject requests that include fields no chain validated
  • matchedData() to extract only the validated/sanitized values into a clean object
  • An extensible ExpressValidator class for registering custom, type-safe validators and sanitizers as first-class chain methods

Common Use Cases

  • Validating and sanitizing form and JSON payload fields on REST API endpoints
  • Normalizing user input (emails, trimming whitespace, escaping HTML) before it hits business logic or storage
  • Enforcing that only expected fields are present in a request body via checkExact()
  • Building reusable validation chains shared across multiple routes in larger Express applications
  • Adding custom domain-specific validators (e.g. checking a value against a database) alongside built-in validator.js rules

Under The Hood

Architecture The public API in src/index.ts and src/express-validator.ts exposes location-scoped chain builders (check, body, query, param, cookie, header) that all funnel through buildCheckFunction() to construct a ValidationChain (src/chain/validation-chain.ts) backed by a Context (src/context.ts) accumulating an ordered stack of ContextItems — standard validations, custom validations, sanitizations, bail conditions, and chain/custom conditions, each in its own file under src/context-items/. Field selection against req.body/query/params/headers/cookies, including dotted paths and wildcard globs, is resolved by src/field-selection.ts and src/context-builder.ts, and a ContextRunner (src/chain/context-runner-impl.ts) executes the stack against the selected field instances as Express middleware. Every Context created for a request is appended to a shared array under a well-known request key, which is how validationResult() and matchedData() later aggregate errors and values across every chain attached to that request without them needing to know about each other.

Tech Stack Written in TypeScript and compiled with tsc, the library has exactly two runtime dependencies: lodash for data grouping/traversal (notably in Context.getData()) and validator for the underlying string validators and sanitizers (isEmail, isURL, escape, etc.) that get wrapped as StandardValidator/StandardSanitizer functions. It has no dependency on Express itself — it is designed to be mounted into any Express-compatible middleware pipeline. Tooling includes ESLint 9’s flat config with eslint-plugin-import and Prettier, Jest 29 with ts-jest for tests, and a separate Docusaurus site under website/ for documentation, published to GitHub Pages after each release.

Code Quality The repo has 22 colocated .spec.ts test files covering the context, chain, context-item, and middleware layers, run via Jest with coverage collection configured to exclude type-only and index files. Internal modules consistently separate a typed interface (validators.ts, context-runner.ts) from its implementation (validators-impl.ts, context-runner-impl.ts), keeping the public surface small while the wiring stays testable in isolation. Linting (ESLint + Prettier) and the test suite both run in CI across six Node.js versions (14 through 24) with coverage submitted to Coveralls on every build, indicating a well-maintained, actively verified codebase.

API Design The chainable syntax (check('email').isEmail().normalizeEmail()) composes validators and sanitizers per field with very little boilerplate, and the location-scoped shortcuts remove the need to specify req.body vs req.query manually. checkSchema() gives a declarative alternative for routes with many fields, while oneOf() and checkExact() cover validation patterns — alternative fields, disallowing unknown fields — that are awkward to hand-roll directly against validator.js. The ExpressValidator factory extends this further, letting teams register custom validators/sanitizers that get full TypeScript inference as chain methods. None of this is conceptually novel for a request-validation library, but the ergonomics and type safety are executed carefully.

Used by 8 apps in this directory

TypeScript
68%
Apache 2.0

Appsmith

Developer Tools · Automation · No Code Platforms

40,825

Open-source low-code platform to build admin panels, dashboards, and internal tools connected to any database or API.

View details
93
Repo Health
79
Technical
66
Dependency
Built with
TypeScript68%
Java21%
Updated 3 days ago
TypeScript
97%
AGPL 3.0

Bigcapital

Invoicing Finance

3,884

Self-hostable double-entry accounting platform with invoicing, inventory, multi-currency, and real-time financial reporting for small and medium businesses.

View details
91
Repo Health
77
Technical
61
Dependency
Built with
TypeScript97%
Updated yesterday
JavaScript
46%
MIT

Kutt

Analytics · Marketing

11,080

Self-hosted URL shortener with custom domains, per-link analytics, and zero build step required.

View details
78
Repo Health
62
Technical
72
Dependency
Built with
JavaScript46%
Handlebars24%
HTML16%
Updated 4 days ago
TypeScript
88%
Apache 2.0

Medplum

Developer Tools · Databases · Authentication

2,657

An open-source, FHIR-native healthcare platform that gives developers a compliant backend, authentication, a React component library, and serverless bots to build clinical applications in weeks instead of years.

View details
93
Repo Health
90
Technical
72
Dependency
Built with
TypeScript88%
MDX10%
Updated yesterday
JavaScript
94%
AGPL 3.0

MyApi

AI Agents

23

A privacy-first personal API gateway for AI agents — connect your services once, issue scoped tokens to agents like OpenClaw, Hermes, or Claude Code, and keep a full audit trail instead of scattering raw credentials across .env files.

View details
30
Repo Health
64
Technical
74
Dependency
Built with
JavaScript94%
Updated 2 weeks ago
TypeScript
91%
AGPL 3.0

PeerTube

Social Media

15,316

A federated, ActivityPub-based video hosting platform built by Framasoft — self-hostable instances interconnect into a network with no vendor lock-in, P2P-assisted streaming, and no ads.

View details
95
Repo Health
75
Technical
70
Dependency
Built with
TypeScript91%
Updated 1 weeks ago
TypeScript
98%
Apache 2.0

Tianji

Analytics · Monitoring

3,086

Replace Google Analytics, UptimeKuma, and Prometheus with one self-hosted platform that tracks websites, monitors uptime, and reports server health.

View details
86
Repo Health
76
Technical
65
Dependency
Built with
TypeScript98%
Updated yesterday
TypeScript
65%
AGPL 3.0

Worklenz

Project Management · Product Management · Collaboration

3,162

All-in-one open source project management for teams who want full control — plan projects, track tasks, manage resources, and monitor finances without the SaaS lock-in.

View details
85
Repo Health
7
Technical
64
Dependency
Built with
TypeScript65%
JavaScript23%
Updated 4 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search