DEV Community

Discussion on: The 5 Must-Know Backend Frameworks in 2024

Collapse
 
mrlinxed profile image
Mr. Linxed

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

GitHub logo MrLinxed / zod-express-middleware

Express middleware to validate requests using zod schema's.

zod-express-middleware

Middleware for express that uses zod to make requests type-safe.

npm npm npm License

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-middleware

Usage

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 app
app.get("/", validateRequest({
    body: z.object({
      bodyKey: z.number(),
    }),
  }), (req, res) => {
    // req.body is now
Enter fullscreen mode Exit fullscreen mode
Collapse
 
sufian profile image
Sufian mustafa

Absolutely! Express.js is awesome to work with. Its simplicity and the availability of great middleware make it super handy