
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
@esmj/schema-express-middleware
Advanced tools
Middleware for express that uses @esmj/schema to make requests type-safe.
Express middleware for validating request body, query, params, and headers using @esmj/schema. Inspired by popular validation middlewares like zod-express-middleware and express-joi-validation, but using @esmj/schema for fast, type-safe validation.
npm install @esmj/schema-express-middleware
import express from 'express';
import { s, validateBody } from '@esmj/schema-express-middleware';
const app = express();
app.use(express.json());
const userSchema = s.object({
name: s.string().min(1),
age: s.number().int().min(0),
});
app.post('/users', validateBody(userSchema), (req, res) => {
// req.body is now validated and typed
res.json({ user: req.body });
});
app.listen(3000);
Arguments:
schemas: { body?, query?, params?, headers? } — An object where each property is an optional @esmj/schema SchemaInterface. Each provided schema will be used to validate the corresponding part of the request (req.body, req.query, req.params, req.headers).errorHandler (optional): (opts) => unknown — A function called on validation error. Receives an object with { req, res, next, part, error, result }.
part: One of 'body' | 'query' | 'params' | 'headers' indicating which part failed.error: The validation error (with message and optional cause).result: The failed parse result (with success: false).Returns: Express RequestHandler middleware.
import { validate, s } from '@esmj/schema-express-middleware';
app.post(
'/login',
validate({
body: s.object({ username: s.string(), password: s.string() }),
query: s.object({ next: s.string().optional() }),
}),
(req, res) => {
// req.body and req.query are validated and typed
res.send('ok');
}
);
You can provide a custom error handler to control the response:
import { validate } from '@esmj/schema-express-middleware';
function myErrorHandler({ res, error, part }) {
res.status(422).json({ part, message: error.message });
}
app.post('/users', validate({ body: userSchema }, myErrorHandler), handler);
Arguments:
schema: [@esmj/schema SchemaInterface] — The schema to validate req.body.errorHandler (optional): Same as above.Returns: Express RequestHandler middleware.
app.post('/users', validateBody(userSchema), handler);
Arguments:
schema: [@esmj/schema SchemaInterface] — The schema to validate req.query.errorHandler (optional): Same as above.Returns: Express RequestHandler middleware.
app.get('/search', validateQuery(s.object({ q: s.string() })), handler);
Arguments:
schema: [@esmj/schema SchemaInterface] — The schema to validate req.params.errorHandler (optional): Same as above.Returns: Express RequestHandler middleware.
app.get('/users/:id', validateParams(s.object({ id: s.string() })), handler);
Arguments:
schema: [@esmj/schema SchemaInterface] — The schema to validate req.headers.errorHandler (optional): Same as above.Returns: Express RequestHandler middleware.
app.get('/secure', validateHeaders(s.object({ authorization: s.string() })), handler);
req.body, req.query, req.params, and req.headers are typed according to your schema.MIT
FAQs
Middleware for express that uses @esmj/schema to make requests type-safe.
The npm package @esmj/schema-express-middleware receives a total of 1 weekly downloads. As such, @esmj/schema-express-middleware popularity was classified as not popular.
We found that @esmj/schema-express-middleware demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.