forked from kerriannercrawford/mern-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (22 loc) · 760 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
const express = require('express');
const path = require('path');
const mongoose = require('mongoose');
// mongoose DB url
const CONNECTION_URL = '';
const PORT = 3000;
const app = express();
const mainRouter = require('./routes/mainRouter.js');
mongoose
.connect(CONNECTION_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => app.listen(PORT, () => console.log('Connected to Database')))
.catch((err) => console.log(err.message));
mongoose.set('useFindAndModify', false);
app.use(express.static(__dirname + '/public'));
app.listen(PORT, () => console.log(`Listening on port ${PORT}`));
app.get('/home', (req, res) => {
res.sendFile(path.resolve(__dirname + '/public/index.html'));
});
app.use('/api', mainRouter);