👨💻 Professional problem solver - 🎧 Music lover
Hello! Thanks for checking out my profile.
If you haven't yet, make sure to also follow me on my other social media! ⬇️
Express middleware to validate requests using zod schema's.
zod-express-middleware
Middleware for express that uses zod to make requests type-safe.
Installation
This package relies on zod, express and @types/express. These have been added as peer dependencies so they can be upgraded independently of this package.
This package provides the validateRequest function, which can be used to validate the .body, .query and .params properties of an Express Request. Separate functions for each of these are also provided (validateRequestBody, validateRequestQuery and validateRequestParams).
Basic example:
import{validateRequest}from'zod-express-middleware';import{z}from'zod';// app is an express appapp.get("/",validateRequest({body: z.object({bodyKey: z.number(),}),}),(req,res)=>{// req.body is now
AI-powered Web developer focused on Next.js + Sanity. Here I share how artificial intelligence is transforming development, programming, and technical SEO strategies. Explore more at doitwithai.tools.
Express.js is super nice to work with. On its own, it's already useful. There are some great middleware's out there and it's easy to build on top of.
One of my repo's
Express middleware to validate requests using zod schema's.
zod-express-middleware
Middleware for express that uses zod to make requests type-safe.
Installation
This package relies on zod, express and @types/express. These have been added as peer dependencies so they can be upgraded independently of this package.
zod-express-middleware can be installed using:
npm install zod-express-middlewareUsage
This package provides the
validateRequestfunction, which can be used to validate the.body,.queryand.paramsproperties of an ExpressRequest. Separate functions for each of these are also provided (validateRequestBody,validateRequestQueryandvalidateRequestParams).Basic example:
Absolutely! Express.js is awesome to work with. Its simplicity and the availability of great middleware make it super handy