Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active December 4, 2019 03:41
Show Gist options
  • Select an option

  • Save harrisonmalone/3a104333a5f02dc8877928ef8a080210 to your computer and use it in GitHub Desktop.

Select an option

Save harrisonmalone/3a104333a5f02dc8877928ef8a080210 to your computer and use it in GitHub Desktop.
NODE_ENV=production
const express = require('express')
require('dotenv').config()
const app = express()
const someMiddleWare = (req, res, next) => {
try {
next()
} catch(err) {
next(err)
}
}
app.get('/', someMiddleWare, (req, res, next) => {
try {
throw Error('badddd!')
} catch(err) {
next(err)
}
})
app.use((err, req, res, next) => {
res.status(500).send('throw an error')
})
app.listen(5000, () => console.log('listening on port 5000 '))
{
"name": "next-err",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^8.2.0",
"express": "^4.17.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment