Registry / web-framework / express-validation

express-validation

JSON →
library4.1.1jsnpmunverified

express-validation v4.1.1 is an Express middleware that validates request parameters (body, query, headers, params, cookies, signedCookies) using Joi schemas. It returns structured error responses when validation fails and integrates with Express error handlers. The library has a hard dependency on Joi v17.x.x and ships with TypeScript definitions. It is actively maintained with regular releases, and provides multiple error format options including keyByField. Compared to alternatives like express-validator, it uses Joi directly rather than its own validator.

web-frameworkserialization
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ESM import; CommonJS destructure works too.

import { validate } from 'express-validation'

Named export for error class.

import { ValidationError } from 'express-validation'

Re-exported Joi from express-validation for convenience.

import { Joi } from 'express-validation'

Sets up an Express app with POST /login route that validates email and password using Joi schemas via express-validation middleware and handles errors with a custom error handler.

import express from 'express'; import { validate, ValidationError, Joi } from 'express-validation'; const loginValidation = { body: Joi.object({ email: Joi.string().email().required(), password: Joi.string().regex(/[a-zA-Z0-9]{3,30}/).required(), }), }; const app = express(); app.use(express.json()); app.post('/login', validate(loginValidation, {}, {}), (req, res) => { res.json(200); }); app.use((err, req, res, next) => { if (err instanceof ValidationError) { return res.status(err.statusCode).json(err); } return res.status(500).json(err); }); app.listen(3000);
Debug
Known footguns
breakingIn v4, the response structure changed from { status, message, errors } to include 'details' object keyed by parameter type.
deprecatedThe old pattern of using Joi directly from 'joi' package is deprecated; express-validation re-exports Joi to ensure version compatibility.
gotchaThe validate() function's second and third parameters (options and joiOptions) are optional but must be passed as objects; passing nothing causes runtime errors.
breakingIn v3, errors were returned as an array; v4 changed to an object keyed by parameter.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
13 hits · last 30 days
gptbot
4
ahrefsbot
4
amazonbot
4
script
1
Resources