-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (30 loc) · 872 Bytes
/
index.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
const mongoose = require("mongoose");
const config = require("./utils/config");
const app = require("./app");
console.log("Starting app..");
console.log("Waiting for connection to MongoDB");
const PORT = config.PORT || 3000;
mongoose
.connect(config.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("✅ Connected to MongoDB!");
console.log("Starting the server ...");
app.listen(PORT, () => {
console.log(`✅ Server is running on PORT ${PORT}`);
});
})
.catch((err) => {
console.log(err);
console.log("Could not connect to MongoDB server! Shutting down...");
process.exit(1);
});
process.on("unhandledRejection", (err) => {
console.log(err.name, err);
console.log("UNHANDLED REJECTION! 💥 Shutting Down...");
app.close(() => {
process.exit(1);
});
});