To redirect user’s browser URL to a different page in Node.js, we call the Express res.redirect
method.
For instance, we write
const express = require("express");
const app = express();
app.get("*", (req, res) => {
res.redirect("https://www.example.com/");
});
app.set("port", process.env.PORT || 3000);
const server = app.listen(app.get("port"), () => {});
to call res.redirect
to redirect to https://www.example.com in the catch get route we created.