-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (34 loc) · 1.14 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// require Express application framework
const express = require('express');
// require Handlebars templating engine for Express
const exphbs = require('express-handlebars');
require('dotenv').config();
const cookieParser = require('cookie-parser');
const app = express();
//serving public file
app.use(express.static(__dirname));
//allow node to use cookies
app.use(cookieParser());
//get body from request
const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({
extended: true
}));
/**bodyParser.json(options)
* Parses the text as JSON and exposes the resulting object on req.body.
*/
app.use(bodyParser.json());
//Set port for heroku
app.set('port', (process.env.PORT || 5000));
//serve static files
app.use(express.static(__dirname + '/public'));
// use Handlebars as templating engine instead of Express default one
app.engine('handlebars', exphbs({defaultLayout: 'base'}));
app.set('view engine', 'handlebars');
//Init router(s)
const peopleRouter = require('./routers/people');
app.use(peopleRouter);
//Start app on port
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});