forked from Trisha-tech/MultiVender-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (29 loc) · 854 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const app = require("./app");
const connectDatabase = require("./db/Database");
// Handling uncaught Exception
process.on("uncaughtException", (err) => {
console.log(`Error: ${err.message}`);
console.log(`shutting down the server for handling uncaught exception`);
});
// config
if (process.env.NODE_ENV !== "PRODUCTION") {
require("dotenv").config({
path: "config/.env",
});
}
// connect db
connectDatabase();
// create server
const server = app.listen(process.env.PORT, () => {
console.log(
`Server is running on http://localhost:${process.env.PORT}`
);
});
// unhandled promise rejection
process.on("unhandledRejection", (err) => {
console.log(`Shutting down the server for ${err.message}`);
console.log(`shutting down the server for unhandle promise rejection`);
server.close(() => {
process.exit(1);
});
});