npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@luolapeikko/express-standard-schema

v0.0.8

Published

ExpressJS Standard Schema Validation Middleware

Readme

@luolapeikko/express-standard-schema

TypeScript npm version Maintainability Code Coverage CI/CD

ExpressJS Standard Schema middleware for request validation.

  • Seamlessly integrates with ExpressJS error middleware by passing a ValidateRequestError instance.
  • Fully compatible with Standard Schema libraries like Zod, ArkType, Valibot, and others.
  • Provides StandardMiddlewareObject helper TypeScript type for the satisfies operator, a structured type for defining request validation schemas.
  • Offers StandardRequestInfer and StandardRequestHandlerInfer for automatic type inference.

Install

npm i express @luolapeikko/express-standard-schema
npm i @types/express @types/express-serve-static-core @standard-schema/spec --save-dev

Usage

import { Router, type ErrorRequestHandler } from "express";
import { z } from "zod";
import {
  validateRequest,
  ValidateRequestError,
  type StandardMiddlewareObject,
  type StandardRequestInfer,
  type StandardRequestHandlerInfer,
} from "@luolapeikko/express-standard-schema";

const router = Router();

const demoRequestSchema = {
  params: z.object({
    id: z.string(),
  }),
  query: z.object({
    filter: z.string().optional(),
  }),
  body: z.object({
    name: z.string().min(3).max(255),
    email: z.string().email(),
  }),
} satisfies StandardMiddlewareObject;

// Infer the Request type only
type DemoRequest = StandardRequestInfer<typeof demoRequestSchema>;

// Infer the RequestHandler type
type DemoRequestHandler = StandardRequestHandlerInfer<typeof demoRequestSchema>;

const handleDemo: DemoRequestHandler = (req, res) => {
  // req.params.id, req.query.filter, and req.body.name are now typed!
  res.status(200).send("OK");
};

// Apply validation to a route
router.put("/user/:id", validateRequest(demoRequestSchema), handleDemo);

// Example Error Middleware
export const errorMiddleware: ErrorRequestHandler = (err, _req, res, next) => {
  if (err instanceof ValidateRequestError) {
    res.status(400).send(`Validation Failed: ${err.message}`);
    // You can also access err.issues for detailed validation errors
    return;
  }
  // handle other errors
};

Advanced type customization

You can extend the inference types to work with your own custom Request and RequestHandler types for even more flexibility.

import type {
  StandardMiddlewareObject,
  StandardParamsInfer,
  StandardBodyInfer,
  StandardQueryInfer,
} from "@luolapeikko/express-standard-schema";

// Integrate Standard Schema inference into your custom Request type.
export type CustomStandardRequest<
  T extends StandardMiddlewareObject,
  ResBody = any,
  Locals extends Record<string, unknown> = Record<string, unknown>,
> = MyBaseRequest<
  StandardParamsInfer<T>,
  ResBody,
  StandardBodyInfer<T>,
  StandardQueryInfer<T>,
  Locals
>;

type DemoRequest = CustomStandardRequest<typeof demoRequestSchema>;

// build RequestHandler type which uses CustomStandardRequest
export type CustomStandardRequestHandler<
  T extends StandardMiddlewareObject,
  ResBody = any,
  Locals extends Record<string, unknown> = Record<string, unknown>,
> = (
  req: CustomStandardRequest<T, ResBody, Locals & LocalsTokenPayload>,
  res: Response<ResBody, Locals & LocalsTokenPayload>,
  next: NextFunction,
) => void;

type DemoRequestHandler = CustomStandardRequestHandler<
  typeof demoRequestSchema
>;