How does assert (req.assert) work in nodejs


I am currently working on MEAN stack using node, express and angularjs. I downloaded boiler plate code from 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?


It’s defined in Express’s dependency express-validator. Check here:

which depends on validator:

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

Leave a Reply

(*) Required, Your email will not be published