Corbi
Corbi

Reputation: 1

Node.js / Express, can't get req.query

I try to retrieve datas with request.query, but it does not work :

app.get('/test/', aFunction);

curl localhost:3000/test/?username=hello&password=word

result :

console.log(request.query); // { username: 'hello' }

Why password is missing in request.query ? I try :

app.get('/test/:param', aFunction);

curl localhost:3000/test/yop?username=hello&password=word

Same thing, password is missing i only have username in request.query

Any idea ?

Thank you

Upvotes: 0

Views: 588

Answers (1)

mscdex
mscdex

Reputation: 106696

The problem is your call to curl. When calling curl in your shell you need to either escape ampersands or put the whole url in quotes, otherwise your shell sees the ampersand and tries to background the process using the command line up to that ampersand.

Try this instead: curl "localhost:3000/test/?username=hello&password=word"

Upvotes: 2

Related Questions