POST Data JSON Validation in Express.js POST Data JSON Validation in Express.js express express

POST Data JSON Validation in Express.js


node-validator is what you are looking for. You can use it as a standalone module like this

var check = require('validator').check;//Validatecheck('test@email.com').len(6, 64).isEmail();        //Methods are chainablecheck('abc').isInt();                                //Throws 'Invalid integer'

Or you can use express-validator which is built on top of node-validator as a middleware.


Here is a more recent benchmark of various JSON schema validators.

Also, for best practices you may want to check out JSON-schema which attempts to lay out a standard way of defining how a JSON object should be defined.