Socket
Socket
Sign inDemoInstall

@ajoelp/express-validator

Package Overview
Dependencies
4
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ajoelp/express-validator

Validation middleware for express


Version published
Weekly downloads
3
Maintainers
1
Install size
6.69 MB
Created
Weekly downloads
 

Readme

Source

Express Validator

Installation

## npm
npm i @ajoelp/express-validator

## yarn
yarn add @ajoelp/express-validator

Usage

import express from 'express';
import {body, query, params, validationResponseMiddleware} from '@ajoelp/express-validator'

const app = express();

app.get(
    '/',
    [
        query({
            'search': ['required', 'string'],
        }),
        params({
            'userId': ['required', 'number'],
        }),
        body({
            'email': ['required', 'email'],
            'password': ['required', { type: 'string', message: 'This needs to be a string'}],
        }),
        validationResponseMiddleware,
        (req, res) => res.send()
    ]
)

// express app setup...

Rules

RuleRule StringRule Object
RequiredRulerequired{ type: 'required', message: 'This is the message'}
StringRulestring{ type: 'string', message: 'This is the message'}
NumberRulenumber{ type: 'number', message: 'This is the message'}
MinRule{ type: 'min', value: 3, message: 'This is the message'}
MaxRule{ type: 'max', value: 4, message: 'This is the message'}
BooleanRuleboolean{ type: 'boolean', message: 'This is the message'}
EmailRuleemail{ type: 'email', regex: new RegExp(), message: 'This is the message'}
DateRuledate{ type: 'date', message: 'This is the message'}
NullableRulenullable
CustomRule{ type: 'custom', rule: (value: string, request: Request) => Promise<boolean>, message: 'This is the message'}

Keywords

FAQs

Last updated on 01 Dec 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc