Skip to content
RED SAG Skills
easyStudy question · answer published in REST API interview questions, so no pointsapi-designexpressvalidation

Route parameter never matches a number

In Express, a route /orders/:id runs this check. For a request to /orders/42 it always says not found. Why?

app.get('/orders/:id', (req, res) => {
  const order = orders.find(o => o.id === req.params.id)
  if (!order) return res.sendStatus(404)
  res.json(order)
})
// orders = [{ id: 42, ... }]
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions