res.download express code example

Example 1: 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 2: express redirect

res.redirect('/foo/bar')
res.redirect('http://example.com')
res.redirect(301, 'http://example.com')
res.redirect('../login')

Example 3: response.render

// here you set that all templates are located in `/views` directory
app.set('views', __dirname + '/views');

// here you set that you're using `ejs` template engine, and the
// default extension is `ejs`
app.set('view engine', 'ejs');

// here you render `orders` template
response.render("orders", {orders: orders_json});

Tags:

Misc Example