Node.js Express redirect example

HTTP Redirects are used to send users’ browsers to another page instead of the current one. There are 2 types of redirects, a 302 redirect…

The post Node.js Express redirect example appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven

HTTP Redirects are used to send users’ browsers to another page instead of the current one. There are 2 types of redirects, a 302 redirect which is considered temporary, and a 301 redirect which is considered permanent. The only difference between them is that the browser can cache and remember the 302 redirects so that the original request need not be made again.

Node.js Express redirect example

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

app.get('/new', (req, res) => {
  res.send('Redirected to new route');
});

Redirects can be relative to the root of the host name or can be relative to the current URL.It can also be a fully-qualified URL for redirecting to a different site:

res.redirect('http://www.google.com')

A back redirection redirects the request back.

res.redirect('back')

The post Node.js Express redirect example appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven


Print Share Comment Cite Upload Translate Updates
APA

Deven | Sciencx (2021-10-19T05:38:01+00:00) Node.js Express redirect example. Retrieved from https://www.scien.cx/2021/10/19/node-js-express-redirect-example/

MLA
" » Node.js Express redirect example." Deven | Sciencx - Tuesday October 19, 2021, https://www.scien.cx/2021/10/19/node-js-express-redirect-example/
HARVARD
Deven | Sciencx Tuesday October 19, 2021 » Node.js Express redirect example., viewed ,<https://www.scien.cx/2021/10/19/node-js-express-redirect-example/>
VANCOUVER
Deven | Sciencx - » Node.js Express redirect example. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/19/node-js-express-redirect-example/
CHICAGO
" » Node.js Express redirect example." Deven | Sciencx - Accessed . https://www.scien.cx/2021/10/19/node-js-express-redirect-example/
IEEE
" » Node.js Express redirect example." Deven | Sciencx [Online]. Available: https://www.scien.cx/2021/10/19/node-js-express-redirect-example/. [Accessed: ]
rf:citation
» Node.js Express redirect example | Deven | Sciencx | https://www.scien.cx/2021/10/19/node-js-express-redirect-example/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.