Node (Express) request body empty
You mention that you post JSON data ({"name": "foobar"}
). Make sure that you send Content-Type: application/json
with that, or bodyParser
will not parse it.
E.g.:
$ curl -d 'user[name]=tj' http://local/$ curl -d '{"user":{"name":"tj"}}' -H "Content-Type: application/json" http://local/
This is because bodyParser
parses application/json
, application/x-www-form-encoded
and multipart/form-data
, and it selects which parser to use based on the Content-Type
.