-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
45 lines (40 loc) · 1.29 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
import app from "./server.js"
import mongodb from "mongodb"
import dotenv from "dotenv"
import UserDAO from "./dao/userDAO.js"
import ContactsDAO from "./dao/contactsDAO.js"
import RelationDAO from "./dao/relationsDAO.js"
dotenv.config() //load the env variables
const MongoClient = mongodb.MongoClient
const port = process.env.PORT || 5000 //get the port value from dotenv
console.log("port is::", port)
//connect to the db
MongoClient.connect(
process.env.C_TRACKER_DB_URI,
{
poolSize: 50, //50 people can connect at a time
wtimeout: 2500, // req timeouts every 2500ms
useNewUrlParser: true,
useUnifiedTopology: true
}
)
.catch(err =>{
console.error(err.stack)
process.exit(1)
})
.then(async client => { // starting the web server
await UserDAO.injectDB(client)
await ContactsDAO.injectDB(client)
await RelationDAO.injectDB(client)
if(process.env.NODE_ENV === "production"){
console.log("inside")
app.use(express.static("client/build"));
const path = require("path");
app.get("*",(req,res)=>{
res.sendFile(path.resolve(__dirname, 'client','build','index.html'));
})
}
app.listen(port ,'0.0.0.0',()=>{
console.log(`listening on port ${port}`)})
}
)