Created
September 29, 2019 11:14
-
-
Save irfanbaigse/f4f6472827d18d8a749fbfe3b883d53e to your computer and use it in GitHub Desktop.
Express 500 error handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = express(); | |
// define your custom routes here | |
app.use('/test', (req, res) => { | |
res.status(200).json({ message: 'your test route' }); | |
); | |
// 500 - Any server error - at the end | |
app.use((err, req, res, next) => { | |
return res.status(500).json({ error: err.toString() }); | |
}); | |
app.server = http.createServer(app); | |
app.server.listen('7595', () => { | |
console.log('server started on => http://localhost:7595'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment