Benjamin E.
Benjamin E.

Reputation: 5172

Express does not return all query string parameters

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 '&'

Upvotes: 13

Views: 4140

Answers (2)

Akash
Akash

Reputation: 5231

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'

Upvotes: 32

steveteuber
steveteuber

Reputation: 182

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

Upvotes: 1

Related Questions