-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
48 lines (26 loc) · 845 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
39
40
41
42
43
44
45
46
47
const app = require("./app")
const mongoose = require("mongoose");
// Handling Uncaught Exception
process.on("uncaughtException", (err) => {
process.exit(1);
});
//Config
if (process.env.NODE_ENV !== "PRODUCTION") {
require("dotenv").config({ path: ".env" });
}
// DB config
const db = require('./config/keys').mongoURI;
if (process.env.NODE_ENV !== "PRODUCTION") {
require("dotenv").config({ path: "config.env" });
}
// connect to MongoDB;
mongoose
.connect(db, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false })
.then(() => console.log("MongoDB Connected"))
.catch(err => console.log(err));
//Init Middleware
if (process.env.NODE_ENV !== "PRODUCTION") {
require("dotenv").config({ path: ".env " });
}
const server = app.listen(process.env.PORT || 4000, () => {
});