-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (41 loc) · 1.42 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
48
49
50
51
let express = require('express');
let mongoose = require("mongoose");
const {Users} = require('./models/user')
const bodyParser = require('body-parser');
const cors = require("cors");
const path = require('path');
mongoose.connect(`mongodb+srv://Sandeep:[email protected]/test`,{useNewUrlParser: true,useUnifiedTopology: true})
.then((data)=>{console.log("successfully connected to db")})
.catch((err)=>{console.log("error connecting to db",err)})
mongoose.set('useNewUrlParser', true);
mongoose.set('useUnifiedTopology', true);
mongoose.set('useFindAndModify', false);
let app =express();
const userRoute = require('./routes/authRoutes');
const profileRoute = require('./routes/Profiles');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cors());
app.use('/api/users',userRoute);
app.use('/api/profile',profileRoute);
app.get("/",(req,res)=>{
res.send("hello world");
})
if(process.env.NODE_ENV === 'production'){
console.log("running production true");
app.use(express.static('client/build'));
app.get('*',(req,res)=>{
res.sendFile(path.join(__dirname,'client','build','index.html'));
})
}else{
app.get("/", (req,res)=>{
res.send("Api running");
})
}
const port = process.env.PORT || 8000
app.listen(port,()=>{
console.log(`App is listening to port ${port}`);
})
/* server.listen(8080,()=>{
console.log("server is listening ro port 8k");
}); */