-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
31 lines (25 loc) · 978 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
// we need this to be at the top so we can deal with EVERY unhandledException
const errorHandling = require("./utils/errorHandling");
errorHandling.handleUncaught("unhandledException");
const dotenv = require("dotenv");
const ENV = `${__dirname}/config.env`;
dotenv.config({ path: ENV });
const mongoose = require("mongoose");
// app comes after dotenv config so that it has access to .env variables
const app = require("./app");
const PORT = process.env.PORT || 3000;
const DB = process.env.DATABASE_URL.replace(
/<PASSWORD>/g,
process.env.DATABASE_PASSWORD
);
mongoose
.connect(DB)
.then((connection) => console.log("Connected to the database!"));
const server = app.listen(PORT, () => {
console.log(`App running on port ${PORT}...`);
});
errorHandling.handleUncaught("unhandledRejection", server);
process.on("SIGTERM", () => {
console.log("SIGTERM RECEIVED; shutting down gracefully.");
server.close(() => console.log("Server shut down complete."));
});