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 e 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?
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 e 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?
Share Improve this question edited May 1, 2014 at 20:17 raju asked May 1, 2014 at 19:51 rajuraju 4,99817 gold badges66 silver badges121 bronze badges 1- This is one of the hardest parts of JavaScript: A function can be defined anywhere, not just where its siblings or containing object are defined. – Brandon Commented May 1, 2014 at 20:01
2 Answers
Reset to default 10It's defined in Express's dependency express-validator. Check here: https://github./ctavan/express-validator/blob/master/lib/express_validator.js
which depends on validator: https://github./chriso/validator.js
Accepted answer refers to what is now the Legacy API hence broken links.
Check out the documentation for Sanitization and the available sanitizing tools. You can make custom validators in there.