-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (42 loc) · 1.07 KB
/
index.js
File metadata and controls
52 lines (42 loc) · 1.07 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
import chalk from 'chalk';
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import router from './server/index.js';
import express from 'express';
import bodyparser from 'body-parser';
import morgan from 'morgan';
import cors from 'cors';
import path from 'path';
const app = express();
dotenv.config();
const db = process.env.MONGODB_URI;
const port = process.env.PORT || 5555;
app.use(
bodyparser.urlencoded({
extended: true,
})
);
app.use(morgan('dev'));
app.use(bodyparser.json());
app.use(cors());
app.use('/', router);
if (process.env.NODE_ENV === 'production') {
app.use(express.static('./build'));
app.get('*', (req, res) => {
res.sendFile(
path.join(path.resolve(path.dirname('')), '/build/index.html')
);
});
}
mongoose
.connect(db, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log(chalk.yellowBright('MONGODB Connected'));
app.listen(port, () => {
console.log(chalk.bgBlueBright.black(`App listening on port ${port}`));
});
})
.catch((err) => console.log(err.message));