Saturday, 16 March 2019

Express: res.location(path): Set location header


res.location(path)
Location header indicates the url to redirect the page to given location.

Example
res.location(' https://self-learning-java-tutorial.blogspot.com)

index.js
'use strict'

const express = require('express')

const app = express()

app.get('/', (req, res) => {
 res.location(' https://self-learning-java-tutorial.blogspot.com')
 
 res.send("Hello World")
})

const port = 3000
app.listen(port, () => console.log(`Application started listening on port ${port}!`))

Run index.js

Open the url ‘http://localhost:3000/’ in browser.


You can see below message.



Previous                                                 Next                                                 Home

No comments:

Post a Comment