2

I use express framework and react on front app for manage http request on node app. A have method :

app.get('/api/matches', async (req, res) =>  {
 console.log(req.originalUrl); // /api/matches/
 console.log(req.query); // {}
 ...

when I use url like http://localhost:3000/matches?id=123 I expect to get id inside req.query object but instead I get empty {} object. Also I tried to check how express see url using originUrl object, its return without query ?id=123.

Edgaras Karka
  • 7,400
  • 15
  • 61
  • 115
  • 2
    You are using `http://localhost:3000/matches?id=123`, instead of `http://localhost:3000/api/matches?id=123`. Is this a typo? – Héctor Apr 30 '18 at 08:27

1 Answers1

0

You need to use your URL like http://localhost:3000/api/matches/?id=123. Notice that api word. This is because your GET route has /api/matches and request will look for path /api/matches. Doing that change will work for you. Then with that change you will be able to get req.query as {id: 123}

Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62