forked from arvention/ccapdev-mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (32 loc) · 1.16 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
// import module `express`
const express = require('express');
// import module `hbs`
const hbs = require('hbs');
// import module `routes` from `./routes/routes.js`
const routes = require('./routes/routes.js');
// import module `database` from `./model/db.js`
const db = require('./models/db.js');
const app = express();
const port = 9090;
// set `hbs` as view engine
app.set('view engine', 'hbs');
// sets `/views/partials` as folder containing partial hbs files
hbs.registerPartials(__dirname + '/views/partials');
// parses incoming requests with urlencoded payloads
app.use(express.urlencoded({extended: true}));
// set the folder `public` as folder containing static assets
// such as css, js, and image files
app.use(express.static('public'));
// define the paths contained in `./routes/routes.js`
app.use('/', routes);
// if the route is not defined in the server, render `../views/error.hbs`
// always define this as the last middleware
app.use(function (req, res) {
res.render('error');
});
// connects to the database
db.connect();
// binds the server to a specific port
app.listen(port, function () {
console.log('app listening at port ' + port);
});