Query Parameters in Express

noun

say it: “KWEER-ee puh-RAM-uh-terz” /ˈkwɪri pəˈræmətərz/

The name and value pairs after the question mark in a URL, which Express reads into req.query as text.

What are query parameters in Express?

Query parameters are the name=value pairs after the ? in a URL. Express puts them in req.query, always as text, so ?maxPrice=5 arrives as "5"; one that wasn't sent is undefined.

// GET /menu?maxPrice=5
app.get("/menu", (req, res) => {
  const maxPrice = Number(req.query.maxPrice ?? 100);
  res.json(menu.filter((item) => item.price <= maxPrice));
});

In a sentence

  • “The search page sends the shopper's filters as query parameters, such as ?category=shoes&maxPrice=50.”
  • “Query parameters arrive as text, so turn ?page=2 into a number before doing math with it.”

Level: Apprentice · More Node.js terms at this level

Updated