Categories
JavaScript Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *