Categories
JavaScript Answers

How to use multiple parameters in URL in Node.js Express?

Spread the love

To use multiple parameters in URL in Node.js Express, we add multiple parameter placeholders.

For instance, we write

app.get("/fruit/:fruitName/:fruitColor", (req, res) => {
  const data = {
    fruit: {
      apple: req.params.fruitName,
      color: req.params.fruitColor,
    },
  };

  send.json(data);
});

to add the fruitName and fruitColor URL placeholders for the get route.

Then we get their values from the req.params object.

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 *