-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
30 lines (24 loc) · 805 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
const express = require("express");
const path = require('path');
const mongoose = require('mongoose');
require('dotenv').config();
const app = express();
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!");
});
app.get('/api/', (req, res) => {
res.json({hello: 'world'})
});
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'));