Registry /
web-framework / express-zod-validations
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
validateBody
✓ import { validateBody } from 'express-zod-validations'
✗ import validateBody from 'express-zod-validations'
Named export, not default
validate
✓ import { validate } from 'express-zod-validations'
✗ const validate = require('express-zod-validations').validate
ESM-only package; CommonJS require may not work without bundler
expressZodValidations
✓ import { expressZodValidations } from 'express-zod-validations'
✗ import { expressZodValidations } from 'express-zod-validations/middleware'
Global config factory, not from subpath
validateParams
✓ import { validateParams } from 'express-zod-validations'
Named export for params validation
validateQuery
✓ import { validateQuery } from 'express-zod-validations'
Named export for query validation
validateHeaders
✓ import { validateHeaders } from 'express-zod-validations'
Named export for headers validation
Sets up an Express server with Zod body validation middleware using validateBody, checks for errors stored on req, and responds accordingly.
import express from 'express';
import { z } from 'zod';
import { validateBody } from 'express-zod-validations';
const app = express();
app.use(express.json());
const userSchema = z.object({
name: z.string().min(2),
email: z.string().email(),
age: z.number().int().positive().optional(),
});
app.post('/users', validateBody(userSchema), (req, res) => {
const user = req.validationValues.body;
if (req.validationErrors?.body) {
return res.status(400).json({ errors: req.validationErrors.body.errors });
}
res.json({ message: 'User created', user });
});
app.listen(3000);
Debug
Known issues
breakingRequires Express v5 (peer dependency express ^5). Express 5 has breaking changes compared to Express 4 (e.g., async error handling, middleware signatures).fixUse Express 5 exclusively; do not use with Express 4.
affects: >=0.0.0
breakingRequires Zod v4 (peer dependency zod ^4). Zod 4 introduces breaking changes from Zod 3 (e.g., new API for coerce, nullable, etc.).fixUpgrade to Zod 4 and adjust schemas per Zod 4 migration guide.
affects: >=0.0.0
deprecatedNo deprecated features reported in this early version.
gotchaBy default, throwErrors is false and validation errors are stored in req.validationErrors. If you use throwErrors: true, errors are passed to next(error) and must be handled by Express error middleware; otherwise the request will hang.fixEnsure an Express error handler is registered when throwErrors is true, or use default false and check req.validationErrors manually.
affects: >=0.0.0
gotchaWhen overwriteRequest is true, the original req.body, req.params, etc. are replaced with parsed values. This may bypass original type declarations.fixUse overwriteRequest: false (default) and access validated data via req.validationValues to preserve original request properties.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'express-zod-validations' or its corresponding type declarations.
Package not installed or missing TypeScript declaration resolution.
fixRun npm install express-zod-validations. Ensure tsconfig.json has 'moduleResolution': 'node' (or 'bundler') and 'esModuleInterop': true.
TypeError: req.validationValues is undefined
Middleware not applied before route handler, or middleware configuration resets validationValues.
fixEnsure validateBody() (or validate) is used as middleware on the route. Do not spread middleware return value.
Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/express-zod-validations/index.mjs not supported.
Package is ESM-only and cannot be required() in CommonJS context without transpilation.
fixUse import syntax or set type: 'module' in package.json. Alternatively, use a dynamic import: const { validateBody } = await import('express-zod-validations'). Audit
Dependencies
expressrequiredPeer dependency: provides request/response objects for middleware injection
zodrequiredPeer dependency: used for schema definition and validation