How assert (req.assert) works in nodejs

I am currently working on a MEAN stack using node, express and angularjs. I downloaded the boiler plate code from mean.io and also used a debugger while I study the code.

In a controller that receives req and res as parameters, how does req.assert work?

In the file server / controllers / users.js

req.assert('username', 'Username cannot be more than 20 characters').len(1,20); 

adds a validation error even when the username is empty or empty. How to check current username value in req? Where is the assert req function defined.

I come from a java background and find it difficult to find the function code several times, since I will not be sure where it is defined and how it is prototyped. How to read objects and view functions used in javascript correctly?

+6
source share
1 answer

It is defined in an express dependent express validator. Check here: https://github.com/ctavan/express-validator/blob/master/lib/express_validator.js

which depends on the validator: https://github.com/chriso/validator.js

+5
source

All Articles