Node.js: Difference between req.query[] and req.params

user1598019 picture user1598019 · Jan 19, 2013 · Viewed 197.3k times · Source

Is there a difference between obtaining QUERY_STRING arguments via req.query[myParam] and req.params.myParam? If so, when should I use which?

Answer

ruffrey picture ruffrey · Jan 24, 2013

Given this route

app.get('/hi/:param1', function(req,res){} );

and given this URL http://www.google.com/hi/there?qs1=you&qs2=tube

You will have:

req.query

{
  qs1: 'you',
  qs2: 'tube'
}

req.params

{
  param1: 'there'
}

Express req.params >>