Created
December 15, 2018 16:09
-
-
Save alexpermiakov/d63a33e80fbf9ffad296e57bef41289e to your computer and use it in GitHub Desktop.
Add 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
import http from "http"; | |
import express from "express"; | |
import { applyMiddleware, applyRoutes } from "./utils"; | |
import middleware from "./middleware"; | |
import errorHandlers from "./middleware/errorHandlers"; | |
import routes from "./services"; | |
process.on("uncaughtException", e => { | |
console.log(e); | |
process.exit(1); | |
}); | |
process.on("unhandledRejection", e => { | |
console.log(e); | |
process.exit(1); | |
}); | |
const router = express(); | |
applyMiddleware(middleware, router); | |
applyRoutes(routes, router); | |
applyMiddleware(errorHandlers, router); | |
const { PORT = 3000 } = process.env; | |
const server = http.createServer(router); | |
server.listen(PORT, () => | |
console.log(`Server is running http://localhost:${PORT}...`) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment