How to get URL parameters with Node.js and Express?

Sometimes, we want to get URL parameters with Node.js and Express.

In this article, we’ll look at how to get URL parameters with Node.js and Express.

How to get URL parameters with Node.js and Express?

To get URL parameters with Node.js and Express, we can use the req.params property.

For instance, we write

app.get('/documents/:format/:type', (req, res) => {
  const {
    format,
    type
  } = req.params
  //...
});

to get the format and type properties from the req.params object to get the value of the format and type URL parameters.

Conclusion

To get URL parameters with Node.js and Express, we can use the req.params property.