express response redirect code example

Example 1: javascript redirect

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

Example 2: express redirect

res.redirect('/foo/bar')
res.redirect('http://example.com')
res.redirect(301, 'http://example.com')
res.redirect('../login')

Example 3: node js http request express

npm install [email protected]

Example 4: response.render

// here you set that all templates are located in `/views` directory
app.set('views', __dirname + '/views');

// here you set that you're using `ejs` template engine, and the
// default extension is `ejs`
app.set('view engine', 'ejs');

// here you render `orders` template
response.render("orders", {orders: orders_json});

Tags:

Misc Example