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

express-joi-verification

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

express-joi-verification

Express Middleware for verification querystring params and body by Joi

latest
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

express-joi-verification

Version License Downloads Build Status Coverage Status

Express Middleware for verification querystring params and body by Joi

Installation

  npm install express-joi-verification

Dependencies

Joi: Object schema description language and validator for JavaScript objects.

  npm install joi

Usage

  const app = require('express')()
  const Joi = require('joi')
  const BodyParser = require('body-parser')
  const verifiy = require('express-joi-verification')

  // use Joi to create schema
  const schema = {
    params: {
      marketId: Joi.number().required()
    },
    body: {
      name: Joi.string().required(),
      price: Joi.number().required()
    }
  }

  // use express-joi-verification express middleware
  app.post('/goods/:marketId', verifiy(schema), (req, res, next) => {
    // do something with req.params and req.body
  })

  // Express Error Handle
  app.use((err, req, res, next) => {
    // custom error
    if (type(err) === 'VerificationError') {
      // For example: you can set status 400 (Bad Request), send error message and path
      const { message, path } = err
      res.status(400).json({
        msg: message,
        path
      })
    }
  })

Test

  npm i
  npm run test

Keywords

express

FAQs

Package last updated on 03 Jul 2018

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