talira

express-validator

Express middleware that validates and sanitizes requests with validator.js

open sourceMITfree

express-validator is a set of Express middlewares that wrap the validators and sanitizers of validator.js, so you can validate and sanitize request bodies, cookies, headers, params and query strings, and find out whether a request is valid and which data matched. It also works with other HTTP libraries whose request object looks like Express's, such as Restify.

Problems it solves

  • check the fields of an incoming Express request before my route handler runs
  • reject a POST body with a missing or badly formatted email field
  • trim and normalise user input in my Express API

Features

  • validation chains for body, cookies, headers, params and query
  • sanitizers from validator.js
  • schema validation
  • works with Express-like request objects such as Restify

Limitations

  • Needs Node.js 14 or newer1