app.get("/where", (req, res) => {
res.status(301).redirect("https://www.google.com")
}) //You need to include the status (301)
app.get('/', (req, res) => {
res.redirect('/foo/bar');
});
app.get('/', (req, res) => {
res.redirect('/about');
})
res.redirect('/foo/bar')
res.redirect('http://example.com')
res.redirect(301, 'http://example.com')
res.redirect('../login')
res.redirect('https://google.com')
const app = require('express')();
// The `res.redirect()` function sends back an HTTP 302 by default.
// When an HTTP client receives a response with status 302, it will send
// an HTTP request to the URL in the response, in this case `/to`
app.get('/from', (req, res) => {
res.redirect('/to');
});
app.get('/to', (req, res) => res.send('Hello, World!'));
// GET method route
app.get('/', function (req, res) {
res.send('GET request to the homepage')
})
// POST method route
app.post('/', function (req, res) {
res.send('POST request to the homepage')
})
app.all('/secret', function (req, res, next) {
console.log('Accessing the secret section ...')
next() // pass control to the next handler
})
Code Example |
---|
:: |
Javascript :: |
:: js add fields to map |
:: |
Javascript :: |
Javascript :: |
:: filepond remove file after upload |
:: |
:: react js if statement |
:: javascript split text after x characters |
Javascript :: replace in string all occurance jquery |
:: |
Javascript :: this function |
Javascript :: |
:: JavaScript catch() method |
:: |
Javascript :: |
:: |
:: |
Javascript :: |
:: |
:: |
:: |
:: return observable from function angular |
Javascript :: |
Javascript :: what is dotenv in nodejs |
:: |
:: logical operators in javascript |
Javascript :: |
Javascript :: convert text to qr code in angular |