tl;dr: You need to parse the body to get that, you can do app.use(require('body-parser')())
and then change your code with name: req.param('name')
.
So express(and actually node.js http server) will call the request call whenever a http request header have been received and not the body of the request. You have to explicitly read and wait for the body to come and parse it yourself.
Luckily there are express middleware modules that parses the body for you. In this case you are sending a urlencoded/form body, so you need to parse it as such. Use any of these modules according to their examples:
Assuming you use body-parser
, then if you want it to parse the body for all routes then just do app.use(require('body-parser')()
. If you want it to parse the body for a particular route then do this:
bodyParser = require('body-parser')()
app.post '/user', bodyParser, (req, res) ->
res.json name: req.param('name')
Once you got the body parsing right, then you can access it either through req.body
(for example req.body.name
) property or req.param
function(for example req.param('name')
). The latter will also search through query string and url parameters.
Note that if you want to parse a body with attached files(for uploading files) you need a multipart parser and not just a urlencoded one: