-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
37 lines (30 loc) · 1008 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
/*!
* @author Mohamed Muntasir
* @link https://github.com/devmotheg
*/
require("dotenv").config();
process.on("uncaughtException", (err, origin) => {
console.error(`Uncaught exception: ${err}\n${err.stack}\nOrigin: ${origin}`);
console.log("Shutting down...");
process.exit(1);
});
const mongoose = require("mongoose");
const app = require("./app");
mongoose
.connect(process.env.DB.replace(/<password>/, process.env.DB_PASS))
.then(() => console.log("DB connection established..."));
const PORT = process.env.PORT || 3000;
const server = app.listen(PORT, () => {
console.log(`Listening on port ${PORT}...`);
});
process.on("unhandledRejection", (reason, promise) => {
console.error(
`Unhandled rejection: ${promise}\n${reason.stack}\nReason: ${reason}`
);
console.log("Shutting down...");
server.close(err => process.exit(1));
});
process.on("SIGTERM", signal => {
console.log("SIGTERM recieved... Shutting down gracefully!");
server.close(err => process.exit(1));
});