-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
52 lines (35 loc) · 1.22 KB
/
server.js
File metadata and controls
52 lines (35 loc) · 1.22 KB
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
52
const express = require ('express');
// const cookieParser = require('cookie-parser');
const mongoose = require ('mongoose');
const path = require ('path');
const apiRouter = require ('./routes');
const app = express();
const PORT = process.env.PORT || 3001;
// Define middleware here
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// preparing production environment for heroku deployment
if(process.env.NODE_ENV === 'production'){
// this calls the build folder to our server
app.use(express.static('client/build'));
// this will server the index.html from the front end
// app.get('*',(req,res)=>{
// res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
// })
}
// app.use(cookieParser());
app.use(apiRouter);
// configuring AtlasDB connection for Heroku Deployment
mongoose.connect(
process.env.MONGODB_URI || "mongodb://localhost/books",
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
},
() =>{ console.log("Successfully connected to DataBase")}
);
app.listen(PORT, () => {
console.log(`Server listening at http://localhost:${PORT}`);
});