express send response code example
Example 1: express redirect
app.get('/', (req, res) => {
res.redirect('/foo/bar');
});
Example 2: express request path
// GET 'http://www.example.com/admin/new?a=b'
app.get('/admin', (req, res, next) => {
req.originalUrl; // '/admin/new?a=b' (full path with query string)
req.baseUrl; // '/admin'
req.path; // '/new'
req.baseUrl + req.path; // '/admin/new' (full path without query string)
});
Example 3: express set response code
res.status(400);
res.send('None shall pass');