express.js - req.body?

时间:2012-12-23 03:21:46

标签: node.js express

我是js的新手, 我在阅读的代码中看到了很多这个

_.pick(req.body, ' ' , ' ') 

req.body做什么? 我什么时候可以说req.body.something?

2 个答案:

答案 0 :(得分:26)

req.body包含作为POST请求的一部分从客户端发送的参数。请参阅API

// POST user[name]=tobi&user[email]=tobi@learnboost.com
req.body.user.name
// => "tobi"

req.body.user.email
// => "tobi@learnboost.com"

// POST { "name": "tobi" }
req.body.name
// => "tobi"

答案 1 :(得分:0)

(req.body, ' ' , ' ') --> here req is the parameter of your function and using this parameter your can access the properties over then url.
so look this example
suppose this is form 
<form>
enter the name : <input type="text" name="name">
<button type ="submit"> submit </button> 
</form>

so if you want to access the name -- which is filled by the user end.
so for this you can 
do like this->   console.log(req.body.name);  -- this will print the name (property) in console.