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.

npm install express-validation
INSTALL
IMPORT
SIG · EXPRESS-VALIDATION
E
express-validation
web-frameworkjavascriptv4.1.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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.

validate
import { validate } from 'express-validation'
const validate = require('express-validation').validate
ESM import; CommonJS destructure works too.
ValidationError
import { ValidationError } from 'express-validation'
const { ValidationError } = require('express-validation')
Named export for error class.
Joi
import { Joi } from 'express-validation'
import Joi from 'joi'
Re-exported Joi from express-validation for convenience.

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 issues
breakingIn v4, the response structure changed from { status, message, errors } to include 'details' object keyed by parameter type.
fix
Update error handling code to access err.details instead of err.errors.
affects: >=4.0.0
deprecatedThe old pattern of using Joi directly from 'joi' package is deprecated; express-validation re-exports Joi to ensure version compatibility.
fix
Use import { Joi } from 'express-validation' instead of import Joi from 'joi'.
affects: *
gotchaThe validate() function's second and third parameters (options and joiOptions) are optional but must be passed as objects; passing nothing causes runtime errors.
fix
Always pass at least empty objects: validate(schema, {}, {})
affects: >=4.0.0
breakingIn v3, errors were returned as an array; v4 changed to an object keyed by parameter.
fix
If you need array format, use the keyByField option or process the details object.
affects: >=4.0.0 <5
Errors
Common errors & fixes
Cannot find module 'express-validation'
Package not installed or import path incorrect.
fix
Run 'npm install express-validation' and verify import statement.
TypeError: Joi.object is not a function
Joi imported from wrong source or version mismatch.
fix
Use import { Joi } from 'express-validation' instead of import Joi from 'joi'.
ValidationError is not defined
Forgot to import ValidationError or used wrong import pattern.
fix
Add import { ValidationError } from 'express-validation' to error handler.
Upgrade
Version history
4.1.1latest on npm
Audit
Dependencies
joirequiredUsed for defining validation schemas
Agent activity
7 hits · last 30 days
node
6
Resources
express-validation — npm install express-validation · libregistry