Issue
I am currently working on MEAN stack using node, express and angularjs. I downloaded boiler plate code from mean.io and also using debugger while I explore the code.
In the controller which gets 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 into validation error even when the username is empty or null. How do I check for current username value in the req? Where is the assert function of req defined.
I come from java background and find it tricky to find the function code some times as I wont be sure about where is it defined and how is it prototyped. How does one properly read the objects and browse the functions that are being used in javascript?
Solution
It’s defined in Express’s dependency express-validator. Check here: https://github.com/ctavan/express-validator/blob/master/lib/express_validator.js
which depends on validator:
https://github.com/chriso/validator.js
Answered By – Matt
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0