-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
28 lines (26 loc) · 1.03 KB
/
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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const path = require('path');
require('dotenv').config();
app.use(cors());
app.use(bodyParser.json());
/* ========================= */
const connection = "mongodb+srv://" + process.env.DB_username + ":"
+ process.env.DB_password + "@capstonemern.ubkvj.mongodb.net/dashboard_app";
mongoose.connect(connection, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false })
.then(() => console.log("Database connected"))
.catch(err => console.log(err));
/* ========================= */
const pracs = require('./api/pracsApi');
app.use('/api/pracs', pracs);
/* ========================= */
app.use(express.static(path.join(__dirname, '../build')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../build'));
})
/* ========================= */
const port = process.env.PORT || 4000;
app.listen(port, () => console.log("server running"));