-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
47 lines (42 loc) · 1.21 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
const express = require("express");
const http = require("http");
const bodyParser = require("body-parser");
const morgan = require("morgan");
const router = require("./router");
const mongoose = require("mongoose");
const path = require("path");
const isProduction = process.env.NODE_ENV === "production";
const prodUser = process.env.DB_UUID;
const prodPW = process.env.DB_PW;
const prodServer = process.env.DB_URI;
const app = express();
// DB Setup
if (isProduction) {
// production db
mongoose
.connect(
"mongodb+srv://" +
prodUser +
":" +
prodPW +
prodServer +
"?retryWrites=true",
{ useNewUrlParser: true }
)
.then(() => console.log("MongoDB Prod Connected....."))
.catch(err => console.log(err));
} else {
mongoose
.connect("mongodb://localhost:27017/auth", { useNewUrlParser: true })
.then(() => console.log("MongoDB Connected....."))
.catch(err => console.log(err));
}
// App Setup
app.use(morgan("combined"));
app.use(bodyParser.json({ type: "*/*" }));
router(app);
const PORT = process.env.PORT || 5000;
const server = http.createServer(app);
server.listen(PORT, function() {
console.log(`Server running on localhost:${PORT}......`);
});