forked from kartikeya-123/Hacko-4-code4bbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (27 loc) · 805 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
const dotenv = require("dotenv");
const http = require("http");
const app = require("./app");
const config = require("./utils/config");
const mongoose = require("mongoose");
const server = http.createServer(app);
dotenv.config();
console.log("Starting app..");
console.log("Waiting for connection to MongoDB");
mongoose
.connect(config.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
})
.then(() => {
console.log("Connected to MongoDB!");
console.log("Starting webserver..");
server.listen(config.PORT, () => {
console.log(`Server is running on port ${config.PORT}`);
});
})
.catch(() => {
console.log("Could not connect to MongoDB server! Shutting down...");
process.exit(1);
});