Registry / devops / express-standard-schema-validation

express-standard-schema-validation

JSON →
library0.2.3jsnpmunverified

Express middleware for validating request inputs (body, query, params, headers) using any library that implements Standard Schema V1. Current stable version: 0.2.3. Release cadence: infrequent, early-stage. Key differentiators: multi-library support (Joi, Zod, ArkType, Valibot), TypeScript-first, value replacement with original value retention in req.original*. Requires Node >=20 and Express >=4.0.0. Derived from express-joi-validation but generalized for Standard Schema. Configurable per-route or globally with passError, statusCode, and custom error templates.

npm install express-standard-schema-validation
INSTALL
IMPORT
SIG · EXPRESS-STANDARD-S
E
express-standard-schema-validation
devopsjavascriptv0.2.3
harness data pending
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.

createValidator
import { createValidator } from 'express-standard-schema-validation'
const createValidator = require('express-standard-schema-validation').createValidator
Default export does not exist; createValidator is a named export. CJS require works but ESM is recommended.
validator.query
const validator = createValidator(); validator.query(schema)
createValidator.query(schema)
createValidator() returns an instance; query() is a method on that instance, not a static method.
validator.body
import { createValidator } from 'express-standard-schema-validation'; const validator = createValidator(); validator.body(schema)
validator.joi(schema) or any library-specific method
Methods are library-agnostic: .body(), .query(), .params(), .headers(), .fields(). Do not use .joi() or similar.

Shows ESM import, createValidator, Zod schema validation, and value replacement of req.body.

import express from 'express'; import { createValidator } from 'express-standard-schema-validation'; import { z } from 'zod'; const app = express(); const validator = createValidator(); const userSchema = z.object({ name: z.string(), age: z.coerce.number().int().positive(), }); app.post('/user', validator.body(userSchema), (req, res) => { res.json({ message: `Created user ${req.body.name}, age ${req.body.age}` }); }); app.listen(3000);
Debug
Known issues
gotchaValue replacement: After validation, req.body, req.query, req.params, req.headers are replaced with the validated/transformed values. Original values are stored in req.originalBody, etc.
fix
If you need the original raw input, use req.originalBody, req.originalQuery, etc.
affects: >=0.0.0
breakingExpress peer dependency: Requires Express >=4.0.0. Not compatible with Express 3.x or earlier.
fix
Upgrade to Express 4.x or later.
affects: >=0.0.0
gotchaNo library-specific options: Unlike express-joi-validation, this package does not accept Joi-specific validation options. All options must be set on the schema itself.
fix
Use schema methods like .required(), .min(), etc. to configure validation.
affects: >=0.0.0
deprecatedNode.js version requirement: Node >=20.0.0 is required. Older Node versions will cause runtime errors.
fix
Upgrade Node.js to version 20 or higher.
affects: >=0.0.0
gotchaStandard Schema V1 compliance: Only libraries that implement Standard Schema V1 interface are supported. Not all versions of Zod/Joi/ArkType/Valibot may be compliant.
fix
Ensure your validation library version implements Standard Schema V1. Tested with recent versions of Zod, Joi, ArkType, Valibot.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: createValidator is not a function
Wrong import: attempting to import a default export instead of named export.
fix
Use `import { createValidator } from 'express-standard-schema-validation'` (named import).
Cannot find module 'express'
Express is not installed (peer dependency missing).
fix
Run `npm install express`.
ValidationError: "name" is required
Request missing required field; schema validation fails.
fix
Check that the request body/query/params contain all required fields as defined in the schema.
TypeError: Cannot read properties of undefined (reading 'query')
Attempting to call validator.query() without first calling createValidator() or on wrong object.
fix
Call `const validator = createValidator();` then use `validator.query(schema)`.
Upgrade
Version history
0.2.3latest on npm
Audit
Dependencies
expressrequiredpeer dependency; middleware operates on Express request/response objects
Agent activity
2 hits · last 30 days
node
2
Resources
express-standard-schema-validation — npm install express-standard-schema-validation · libregistry