Just a few weeks until the 2021 JavaScript Full-Stack Bootcamp opens.
Signup to the waiting list!
Redirects are common in Web Development. You can create a redirect using the Response.redirect()
method:
res.redirect('/go-there')
This creates a 302 redirect.
A 301 redirect is made in this way:
res.redirect(301, '/go-there')
You can specify an absolute path (/go-there
), an absolute url (https://anothersite.com
), a relative path (go-there
) or use the ..
to go back one level:
res.redirect('../go-there')
res.redirect('..')
You can also redirect back to the Referer HTTP header value (defaulting to /
if not set) using
res.redirect('back')
Download my free Express.js Handbook
The 2021 JavaScript Full-Stack Bootcamp will start at the end of March 2021. Don't miss this opportunity, signup to the waiting list!
More express tutorials:
- Express, a popular Node.js Framework
- Retrieve the GET query string parameters using Express
- Validating input in Express using express-validator
- Express Templates
- Serving Static Assets with Express
- Send a JSON response using Express
- Express Sessions
- Send a response using Express
- Send files using Express
- Sanitizing input in Express using express-validator
- Routing in Express
- An Express HTTPS server with a self-signed certificate
- Express, Request Parameters
- Retrieve the POST query parameters using Express
- Handling redirects with Express
- Express Middleware
- Setup Let's Encrypt for Express
- Work with HTTP headers in Express
- Handling forms in Express
- Handling file uploads in forms using Express
- Handling CORS in Express
- Manage Cookies with Express