express error handling

JavaScript
app.use(function (err, req, res, next) {
  console.error(err.stack)
  res.status(500).send('Something broke!')
})
app.get('/', function (req, res) {
  throw new Error('BROKEN') // Express will catch this on its own.
})

Source

Also in JavaScript: