then/catch express code example
Example 1: node js try catch
try {
nonExistentFunction();
} catch (error) {
console.error(error);
// expected output: ReferenceError: nonExistentFunction is not defined
// Note - error messages will vary depending on browser
}
Example 2: express error handling
app.use(function (err, req, res, next) {
console.error(err.stack)
res.status(500).send('Something broke!')
})