Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-validate-decorator

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-validate-decorator

Validate express routes with Joi. You can validate query and body.

  • 0.2.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
71
decreased by-38.79%
Maintainers
1
Weekly downloads
 
Created
Source

🦈 Express Validate Decorator

Validate express routes with Joi. You can validate query and body.

Example

Create a class for using decorators. When query or body not validated by schema this method will return 400 with Joi validation error message.



import { validate, number, string, schema } from "express-validate-decorator";

import express from "express"
const app = express();
const port = 3000;

class UserService {

    constructor() {
        //validator respects your scope you can use bind safely
        this.getUser = this.getUser.bind(this);
    }
    
    //create validator schema
    @validate({
        query: {
            page: number.required(),
            count: number.required()
        },
        // you can add your custom schema 😱
        body: schema({
            a: Joi.number().min(1).max(10).integer(),
            b: 'some string'
        });
    })
    getUser(req, res){
        //use body or request without if conditions or null checks 
        res.send('Hello World!')
    }
}

const userService = new UserService()

app.get('/',userService.getUser)

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})

FAQs

Package last updated on 09 Dec 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc