-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
62 lines (48 loc) · 1.3 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const express = require('express');
const path = require('path');
const exphbs = require('express-handlebars');
const bodyParser = require('body-parser');
const volleyball = require('volleyball');
const mongoose = require('mongoose');
// Load Models
require('./models/Proposal');
// Load Routes
const index = require('./routes/index');
// Load Keys
const keys = require('./config');
//Handlebars Helpers
const {
truncate,
formatDate,
categoryStr
} = require('./helpers/hbs');
// Map global promises
mongoose.Promise = global.Promise;
// Mongoose Connect
mongoose.connect(keys.mongoURI, { useNewUrlParser: true })
.then(() => console.log('MongoDB Connected'))
.catch(err => console.log(err));
const app = express();
// Body Parser Middleware
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
// log request
app.use(volleyball)
// Handlebars Middleware
app.engine('handlebars', exphbs({
helpers: {
truncate: truncate,
formatDate: formatDate,
categoryStr: categoryStr
},
defaultLayout:'main'
}));
app.set('view engine', 'handlebars');
// Set static folder
app.use(express.static(path.join(__dirname, 'public')));
// Use Routes
app.use('/', index);
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Server started on port ${port}`)
});