13

Route

app.get('/pdf/:id', function(req, res) {

Request

GET http://localhost/pdf/123?option=456&clientId=789

I only get

req.query == { option: '456' }
req.params == { id: '123' }

How comes the second query parameter is cut off? My delimiter is a standard '&'

2 Answers 2

32

If you are using curl or some terminal command, & has a special meaning there. Try gettig it inside quotes as

curl 'http://localhost/pdf/123?option=456&clientId=789'
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I should have mentioned that earlier
Yep... I was having the same problem and stumbled upon this question.
1

This code is working:

app.get('/pdf/:id', function(req, res) {
    console.log(req.params);
    console.log(req.query);

    res.end();
});

Output:

[ id: '123' ]
{ option: '456', clientId: '789' }
GET /pdf/123?option=456&clientId=789 200 1ms

1 Comment

Thanks, but that's exactly what I'm doing, no? Same thing on Express v3 and v4. The only difference I see is that v4 uses an object for req.params, not an array. When I flip the query params, again only the first one is available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.