-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (40 loc) · 1.37 KB
/
index.js
File metadata and controls
51 lines (40 loc) · 1.37 KB
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
const dotenv = require(`dotenv`);
const express = require(`express`);
const hbs = require(`hbs`);
const bodyParser = require(`body-parser`);
const routes = require(`./routes/routes.js`);
const db = require(`./models/db.js`);
const exphbs = require('express-handlebars');
const moment = require('moment');
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.set(`view engine`, `hbs`);
const path = require('path');
dotenv.config();
port = process.env.PORT;
hostname = process.env.HOSTNAME;
app.engine('hbs', exphbs.engine({
extname: 'hbs',
defaultView: 'index',
partialsDir: path.join(__dirname, '/views/partials'),
helpers: {
preview: function(str) {
if (str.length > 100)
return str.substring(0,100) + '...';
return str;
},
// Taken from https://gist.github.com/elidupuis/1468937/caec40920ca76302f0fd3b218a763fa118e1901c
// usage {{dateFormat creation_date format="MMMM YYYY"}}
dateFormat: function(context, block) {
var f = block.hash.format || "MMMM DD YYYY, h:mm a";
return moment(new Date(context), "YYYY-MM-DDTHH:mm:ss.SSSZ").format(f);
}
}
}));
app.use(express.static(`public`));
app.use(`/`, routes);
db.connect();
app.listen(port, hostname, function () {
console.log(`Server is running at:`);
console.log(`http://` + hostname + `:` + port);
});