-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
48 lines (35 loc) · 1.15 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Importing libraries
const express = require('express');
const app = express();
const expbs = require('express-handlebars');
const path = require('path');
// Importing files
const routes = require('./routes/handlers');
// Sending static files with Express
app.use(express.static('public'));
const hbs = expbs.create({
defaultLayout: 'main',
layoutsDir: path.join(__dirname, 'views/mainLayout'), // change layout folder name
partialsDir: path.join(__dirname, 'views/pieces'), // change partials folder name
// create custom express handlebars helpers
helpers: {
calculation: function(value) {
return value * 5;
},
list: function(value, options) {
let out = "<ul>";
for (let i = 0; i < value.length; i++) {
out = out + "<li>" + options.fn(value[i]) + "</li>";
}
return out + "</ul>";
}
}
});
// Express Handlebars Configuration
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');
// Configure Routes
app.use('/', routes);
app.listen(8080, () => {
console.log('Server is starting at port ', 8080);
});