express querys as type code example

Example 1: typescript req.query.query

// req.query.shopEventId is possibly === undefined

if (!req.query.shopEventId) {
	return res.status(400).send()
}

const shopEventId: string = String(req.query.shopEventId)

Example 2: express render

// send the rendered view to the client
res.render('index')

// if a callback is specified, the rendered HTML string has to be sent explicitly
res.render('index', function (err, html) {
  res.send(html)
})

// pass a local variable to the view
res.render('user', { name: 'Tobi' }, function (err, html) {
  // ...
})

Tags:

Html Example