Vadorequest
Vadorequest

Reputation: 17997

How get all parameters in express.js (post/get/etc.)

Is there a way to get in once all parameters sent using express.js? I know how do it to know the GET/POST separately, but is there a way to get everything at once?

I didn't found anything about that so far, it's useful to debug in particular.

Of course the req.param(key) works, but I want to have a list of all parameters, not have to retrieve them, just see them.

Edit: Add Route info:

consoleDev('Url: ' + req.method + ' ' + req.baseUrl + req._parsedUrl.href, 'debug');
consoleDev('Options: ' + JSON.stringify(options), 'debug');
consoleDev('Params: ' + Object.keys(req.params), 'debug');
consoleDev('Params: ' + (req.param('test')), 'debug');

Console:

debug: Url: GET http://localhost:5000/?test=5000
debug: Options: {"controllerName":"home","methodName":"index"}
debug: Params: 
debug: Params: 5000

Upvotes: 3

Views: 10443

Answers (3)

pook developer
pook developer

Reputation: 346

You can use, for query parameters: Object.keys(contexto.req.query);

Upvotes: 0

Vadorequest
Vadorequest

Reputation: 17997

I forgot I created this topic few months ago and created another one where I got the answer to the question:

You're looking for req.body, which contains the parsed POST body. (assuming you have middleware that parses it)

See express.bodyParser()

How log express.js POST parameters

Upvotes: 3

Hector Correa
Hector Correa

Reputation: 26690

If you just want to view the values passed you can just do

console.dir(req.params);

Or you can get the list of keys by using something like this:

keys = Object.keys(req.params);
console.log(keys);

Upvotes: 0

Related Questions