3

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
Vadorequest
  • 16,593
  • 24
  • 118
  • 215

3 Answers3

3

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

Community
  • 1
  • 1
Vadorequest
  • 16,593
  • 24
  • 118
  • 215
0

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);
Hector Correa
  • 26,290
  • 8
  • 57
  • 73
  • 1
    `req.param` is a function. `req.params` is an array, but always empty when I send GET/POST params. – Vadorequest Feb 18 '14 at 22:05
  • My bad. I've just edited my answer to reflect req.params as I originally intended. If the values are empty on POST you might be missing app.use(express.bodyParser()); in your code. But it is rather strange that they are also empty on GET. Could you include your route in your question? – Hector Correa Feb 18 '14 at 22:12
  • Done. What do you think? It just doesn't find the keys but when I call them explicitely it does. – Vadorequest Feb 19 '14 at 07:03
  • req.params will include values in the URL stem. It will catch "test" if your route was app.get("/:test",whatever). To read the query string values you could use req.query. I suspect req.param() is smart enough to parse both (req.params and req.query) – Hector Correa Feb 19 '14 at 14:00
  • Ok, but it's not what I'm looking for. But I guess there is nothing such as I want in express. And yes, req.param is able to provide query, route and post/etc. – Vadorequest Feb 19 '14 at 15:50
0

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

pook developer
  • 188
  • 3
  • 5