Dig Dig - 28 days ago 11
Node.js Question

API queries in Nodejs/Express

why doesn't this work?

/search?name=:name


but this works :

/search/name=:name


how to make the former work with the
?
(Question mark)

str str
Answer

See https://expressjs.com/en/guide/routing.html

Query strings are not part of the route path.

If you want to use the query string, use req.query:

app.get('/search', function (req, res) {
  console.log(req.query);
});