New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

myzod-express

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

myzod-express

MyZod validation middlewares for Express application

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

MyZod Express library

Express middleware to handle requests validation by myzod library. Library can be used for versions 1.x.

Installation

  npm install myzod-express

Usage

Library provided function validateRequest which return RequestHandler middleware.

validateRequest(field: RequestField, schema: MyZodSchema, options?: Options): RequestHandler
  • field (at this moment - body, params, query) parameter specify which Request field should be use during validation,
  • schema parameter is myzod schema,
  • options (optional) parameter stores additional informations.

Additional options

By default, middleware pass ValidationError to the next() function. It can be changed by additional option createAndReturnResponse, which pass ValidationError to response.send() function. If defaultResponseFunc was provide, response.send() will return result of this function.

Response status code can be changed by defaultResponseCode.

MyZod additional options can be passed by myzodOptions.

Usage example

const schema = myzod.object({
  id: myzod.string(),
});

const app: Express = express();

app.get('/', [validateRequest('params', schema), (req, res) => {
  return 'working';
}]);

app.listen(2137, () => {
  console.log('App listen');
});

Project commands

Brief explanation of project NPM commands.

Build

prebuild removes lib directory before each building

  npm run build

Run tests

  npm test

Run tests with coverage

  npm run coverage

Keywords

express

FAQs

Package last updated on 08 Jun 2022

Did you know?

Socket

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.

Install

Related posts