res.redirect([status,]
path)
Redirects the request to this url using given status
code. Status code is optional, if you do not specify the status code, it is 302
by default.
Example
res.redirect(301,
'https://self-learning-java-tutorial.blogspot.com');
res.redirect('https://self-learning-java-tutorial.blogspot.com')
index.js
'use strict' const express = require('express') const app = express() app.get('/', (req, res) => { res.redirect('https://self-learning-java-tutorial.blogspot.com') }) const port = 3000 app.listen(port, () => console.log(`Application started listening on port ${port}!`))
Run the application.
Open the url 'http://localhost:3000/' in browser, you can
see that the url is redirected.
No comments:
Post a Comment