Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 511
Benjamin E. Avatar asked Apr 14 '14 09:04

Benjamin E.


People also ask

Are query params always string?

Yes, URL query string params are of type string.

How do I get query params Express?

Your query parameters can be retrieved from the query object on the request object sent to your route. It is in the form of an object in which you can directly access the query parameters you care about. In this case Express handles all of the URL parsing for you and exposes the retrieved parameters as this object.

How do you get variables in Express JS in the GET method?

In Express. js, you can directly use the req. query() method to access the string variables.

What is a query string in Express?

The query string portion of a URL is the part of the URL after the question mark ? .


1 Answers

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'
like image 168
Akash Avatar answered Sep 28 '22 00:09

Akash