Registry / web-framework / express-yup-middleware

express-yup-middleware

JSON →
library2.0.0jsnpmunverified

Express middleware that validates request body, query, and params using Yup schemas. Version 2.0.0 is the latest stable release. It integrates Yup validation into Express routes and returns structured error responses. Differentiators include custom error messages per field, validation options per schema part (e.g., abortEarly), and cross-validation via context. Requires Yup as a peer dependency.

npm install express-yup-middleware
INSTALL
IMPORT
SIG · EXPRESS-YUP-MIDDLE
E
express-yup-middleware
web-frameworkjavascriptv2.0.0
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.

expressYupMiddleware
import { expressYupMiddleware } from 'express-yup-middleware'
import expressYupMiddleware from 'express-yup-middleware'
Named export, not default. ESM import.
ExpressYupMiddlewareInterface
import { ExpressYupMiddlewareInterface } from 'express-yup-middleware'
TypeScript interface for schema validator objects.
expressYupMiddleware (CommonJS)
const { expressYupMiddleware } = require('express-yup-middleware')
const expressYupMiddleware = require('express-yup-middleware')
CommonJS destructured require.

Basic Express route with body validation using Yup schema and custom error messages.

import express from 'express'; import { expressYupMiddleware } from 'express-yup-middleware'; import * as Yup from 'yup'; const app = express(); app.use(express.json()); const schemaValidator = { schema: { body: { yupSchema: Yup.object().shape({ name: Yup.string().required('name-required'), }), }, }, errorMessages: { 'name-required': { key: 'name-required', message: 'Name is required.', }, }, }; app.post('/test', expressYupMiddleware({ schemaValidator }), (req, res) => { res.json({ message: 'Success' }); }); app.listen(3000);
Debug
Known issues
gotchaThe `schemaValidator` object must have `schema` at the top level with `body`, `query`, or `params` properties; missing them will skip validation without error.
fix
Ensure `schemaValidator` includes at least one of `body`, `query`, `params` inside `schema`.
affects: >=0.0.0
gotchaError messages object keys must exactly match the custom message strings used in Yup's `.required()` etc. (e.g., 'name-required') – not the property path.
fix
Use the same string passed to Yup's validation message as the key in `errorMessages`.
affects: >=0.0.0
gotchaCross-validation via `this.options.context` requires the request object to be passed; the middleware provides `req` in context automatically.
fix
Access `this.options.context` in Yup `.test()` to get the request payload.
affects: >=1.0.0
deprecatedYup v0.x vs v1.x: In Yup v1, `.shape()` may require different import path. express-yup-middleware 2.x supports Yup v1.
fix
Use Yup v1.x and import as `import * as Yup from 'yup'`.
affects: 2.x
Errors
Common errors & fixes
Cannot find module 'express-yup-middleware'
Package not installed or wrong import path.
fix
Run `npm install express-yup-middleware` and use correct import: `import { expressYupMiddleware } from 'express-yup-middleware'`.
TypeError: schemaValidator.schema is undefined
Missing `schema` property in the validator object.
fix
Provide `schema` with at least one key (`body`, `query`, `params`) as shown in docs.
ValidationError: testBodyProperty is required
Yup schema property is required and missing.
fix
Ensure request body includes the required field defined in schema.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
yuprequiredPeer dependency for defining validation schemas.
Agent activity
6 hits · last 30 days
node
6
Resources
express-yup-middleware — npm install express-yup-middleware · libregistry