最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How does assert (req.assert) work in nodejs - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 10

It'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.

发布评论

评论列表(0)

  1. 暂无评论