express redirect to another url code example

Example 1: javascript redirect

window.location.href = "http://mywebsite.com/home.html";

Example 2: express redirect to url

app.get('/', (req, res) => {
  res.redirect('/about');
})

Example 3: express url redirect

const app = require('express')();

// The `res.redirect()` function sends back an HTTP 302 by default.
// When an HTTP client receives a response with status 302, it will send
// an HTTP request to the URL in the response, in this case `/to`
app.get('/from', (req, res) => {
  res.redirect('/to');
});
app.get('/to', (req, res) => res.send('Hello, World!'));