Skip to content

Instantly share code, notes, and snippets.

@irfanbaigse
Created September 29, 2019 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irfanbaigse/f4f6472827d18d8a749fbfe3b883d53e to your computer and use it in GitHub Desktop.
Save irfanbaigse/f4f6472827d18d8a749fbfe3b883d53e to your computer and use it in GitHub Desktop.
Express 500 error handling
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