-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (31 loc) · 970 Bytes
/
app.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
35
36
37
38
39
40
41
require('dotenv').config();
//mongoose
const mongoose = require('mongoose');
mongoose.connect(process.env.DB_URI, {auth: {
user: process.env.DB_USER,
password: process.env.DB_PASS
}, useNewUrlParser: true
}).catch(err => console.error(`ERROR: ${err}`));
const express = require('express');
const path = require('path');
const app = express();
// view path
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
//body parser
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
//our routes
const routes = require('./routes.js');
app.use('/api', routes);
/*// Handles all other requests
app.get('*', (req,res) => {
console.log(req.path);
res.sendFile path.join(__dirname + "/client/build/index.html");
});*/
//dynamic port listening
const port = process.env.PORT || 4000;
app.listen(port, () => console.log(`Listening on port ${port}`));