0

I have a url like this:

http://localhost:3000/hi?key=abcd345&section=you

I need the value of the parameter, section. I use:

req.query.section

But the value is undefined.

I tried testing

console.log(req.url);

But the output is only:

/hi?key=abcd345

And I also tried:

console.log(req.query);

But the output is only:

{"key":"abcd345"}

I dont know what happened to the parameter section. Am I missing something? Please let me know. Thanks.

krisbie
  • 111
  • 1
  • 4
  • 15
  • Possible duplicate of http://stackoverflow.com/questions/6912584/how-to-get-get-query-string-variables-in-node-js – Sarbbottam Jul 21 '14 at 04:51
  • But I also tried the answer from that question. I tried: var url = require('url'); var url_parts = url.parse(request.url, true); var query = url_parts.query; And console.log(query); Still, the only parameter shown is the key.. and there is no section field.. – krisbie Jul 21 '14 at 05:00
  • try req.param("section") – Diya Khan Jul 21 '14 at 05:21
  • `req.query` absolutely should work for this. If we can see all the code, maybe we can help. – Matt Harrison Jul 21 '14 at 06:12
  • 3
    Got it. I found out that the problem is in curl. when passing multiple parameters, it need to put single quotes around the url. Thanks for the help guys! Sorry for not mentioning I am using curl.. – krisbie Jul 21 '14 at 06:43

0 Answers0