Why does req.params return an empty array?


I'm using Node.js and I want to see all of the parameters that have been posted to my script. To get to my function, in my routes/index.js I'm doing:

app.post('/v1/order', order.create);

Then in my function, I have:

exports.create = function(req, res, next) {
 console.log( req.params );

But it's returning an empty array. But when I do:

exports.create = function(req, res, next) {
 console.log( req.param('account_id') );

I get data. So I'm a bit confused as to what's going on here.

Problem courtesy of: Shamoon


req.params only contain the route params, not query string params (from GET) and not body params (from POST). The param() function however checks all three, see:


Solution courtesy of: Marius Kjeldahl


can only get the param of request url in this pattern:/user/:name

get query params(name) like /user?name=123 or body params.

Discussion courtesy of: Eddy

This recipe can be found in it's original form on Stack Over Flow.