I want to know how does EXPRESS parse multiple query parameters with the same name; I couldn't find any useful reference anywhere. I want to know specifically about EXPRESS, how is it going to treat this URL www.example.com/page?id=1&id=2&id=3.....id=n
Asked
Active
Viewed 5,670 times
8

hakiki_makato
- 189
- 2
- 7
-
Does this answer your question? [Correct way to pass multiple values for same parameter name in GET request](https://stackoverflow.com/questions/24059773/correct-way-to-pass-multiple-values-for-same-parameter-name-in-get-request) – Rohit Ambre Jun 26 '20 at 06:22
-
No, it talks about which method is better, not how they work. Also, I think each framework has its own ways to parse things, especially for such corner-cases and that's why I mentioned EXPRESS. I saw that before asking. Thanks anyway! – hakiki_makato Jun 26 '20 at 06:28
-
QueryParser in Express is configurable, the default configuration ("extended") uses [qs](https://www.npmjs.org/package/qs) to parse query strings, the simple mode uses Node’s native query parser [querystring](https://nodejs.org/api/querystring.html), and you can also define your own parser. I couldn't find anything from the linked documentations concerning double names, but you can test it. – Teemu Jun 26 '20 at 06:53
-
Hey @Teemu, thanks for replying, as you mentioned, I've found some correlations. From what I've understood, It's storing them in an array which in my opinion is a good way for bypassing filters for local file inclusion. I just want some concrete documentation or RFC section supporting some similar argument. – hakiki_makato Jun 26 '20 at 07:25
-
As Eduardo has stated in the [suggested dup](https://stackoverflow.com/a/24728298/1169519), "_there is no defined standard_", you've to examine the documentation of the implementations, which in these two cases don't seem to contain the wanted information. Hence the only way to find out is testing ... – Teemu Jun 26 '20 at 07:46
1 Answers
2
You can use the usual req.query. Whenever there's multiple query parameters with the same name, req.query[paramName]
will return an array instead of the value. So in your case:
app.get("/page", (req, res) => {
const { id } = req.query
console.log("ID is "+ id)
});
// GET www.example.com/page?id=1&id=2&id=3
// ID is ["1", "2", "3"]
// GET www.example.com/page?id=12345
// ID is 12345

akmalmzamri
- 1,035
- 1
- 15
- 31