express-in

Middleware for check body and query params

10 months after

Validation body and query params. Using superhero-validator

Install

$ npm install --save express-in

Usage

// validate query params
const validators = require('superhero-validator').validators;
const query = require('express-in').query;

app.get('/', query({
    email: validators.email(),
    name: validators.string(5, 15),
    age: validators.number(21, 100),
    lastname: validators.oneOf([
        validators.empty()
        validators.string(2, 15)
    ])
}), function(req, res) {
    res.send('success'); // if params is invalid, then send error json
});

// validate body (POST) params
const validators = require('superhero-validator').validators;
const body = require('express-in').body;

app.get('/', body({
    email: validators.email(),
    name: validators.string(5, 15),
    age: validators.number(21, 100),
    lastname: validators.oneOf([
        validators.empty()
        validators.string(2, 15)
    ])
}), function(req, res) {
    res.send('success'); // if params is invalid, then send error json
});

// custom error handler

app.use(errorHandler(function(result, req, res, next) {
   // result {success, key, error, message}

   res.send('validation error');
});

more validators on superhero-validator

Related Repositories

grunt-express

grunt-express

Start an Express.js web server using grunt.js ...

grunt-express-server

grunt-express-server

Grunt task for running an Express Server that works great with LiveReload + Watc ...

express-graceful-exit

express-graceful-exit

Gracefully exit Express in order to get zero downtime deploys ...

express-web-components

express-web-components

Declaratively build Express applications with web components. ...

express-oauth-server

express-oauth-server

Complete, compliant and well tested module for implementing an OAuth2 Server/Pro ...