15

I'm new to js, I see this a lot in the code I'm reading

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

What does req.body do? And when can I say req.body.something?

alditis
  • 4,633
  • 3
  • 49
  • 76
User_y
  • 179
  • 1
  • 1
  • 5

2 Answers2

33

req.body holds parameters that are sent up from the client as part of a POST request. See the 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"
Jacob Marble
  • 28,555
  • 22
  • 67
  • 78
TomJ
  • 5,389
  • 4
  • 26
  • 31
  • What happens if something is sent from the server instead of the client and how do you reconcile the two when you get some request from the client and the others from the server? – rashadb May 27 '15 at 22:48
2
(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.