-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
34 lines (26 loc) · 903 Bytes
/
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
const express = require("express");
const path = require('path');
const mongoose = require('mongoose');
const routes = require('./server/routes');
const formData = require('express-form-data');
require('dotenv').config();
const app = express();
app.use(express.json());
app.use(formData.parse());
mongoose.connect(process.env.DB_URL, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
useFindAndModify: false
});
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', () => {
console.log("MongoDB database connection established!");
});
routes(app);
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, '/client/build', 'index.html'));
});
app.listen(process.env.PORT || 4000, () => console.log('APP listening on 4000'));