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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
validate
✓ const validate = require('express-jsonschema').validate;
✗ const validate = require('express-jsonschema');
The default export is an object; validate is a named export. CommonJS only.
JsonSchemaValidation
✓ const JsonSchemaValidation = require('express-jsonschema').JsonSchemaValidation;
✗ const { JsonSchemaValidation } = require('express-jsonschema');
JsonSchemaValidation is a class used for error handling; it is not a default export.
validate (ESM)
✓ import { validate } from 'express-jsonschema';
✗ import validate from 'express-jsonschema';
ESM imports are supported but not documented; use named import.
Demonstrates setting up an Express endpoint with JSON Schema validation for the request body and a custom error handler.
const express = require('express');
const { validate } = require('express-jsonschema');
const app = express();
app.use(require('body-parser').json());
const schema = {
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'number' }
},
required: ['name']
};
app.post('/user', validate({ body: schema }), (req, res) => {
res.json({ valid: true });
});
app.use((err, req, res, next) => {
if (err.name === 'JsonSchemaValidation') {
res.status(400).json({ errors: err.validations });
} else {
next(err);
}
});
app.listen(3000);
Errors
Common errors & fixes
TypeError: validate is not a function
Attempted to use default import without destructuring.
fixUse const { validate } = require('express-jsonschema'); Cannot read property 'body' of undefined
The validate() call is missing the request property key, e.g., validate({ body: schema }).
fixPass an object with key 'body', 'query', or 'params'.
Audit
Dependencies
jsonschemarequiredCore validation library; express-jsonschema wraps jsonschema to provide Express middleware.