Categories
JavaScript Answers

How to redirect a user to an external URL with Node Express?

Spread the love

To redirect a user to an external URL with Node Express, we call res.status and redirect.

For instance, we write

app.get("/where", (req, res) => {
  res.status(301).redirect("https://www.example.com");
});

to call res.status with 301 to return the 301 moved permanently status.

And then we call redirect to redirect to https://www.example.com.

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 *