-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (39 loc) · 938 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
require('dotenv').config();
const express = require('express');
const morgan = require('morgan');
const cors = require('cors');
const apiRouter = require('./routes/ApiRouter');
const mongoose = require('mongoose');
const path = require('path');
// initialising
const app = express();
// cors
app.use(cors());
// morgan
app.use(morgan('dev'));
// body parsing
app.use(express.json());
// backend routing link
app.use('/api/v1/to-do', apiRouter);
// mongodb init
mongoose.connect(
process.env.DB_CONNECTIONSTRING,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
},
() => {
console.log('Database Connected');
}
);
// for prod
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, 'client/build')));
}
// server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`I love you ${PORT}`);
});