-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (37 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
const express = require("express");
const app = express();
const port = process.env.PORT || 4000;
const expressHbs = require("express-handlebars")
app.use(express.static(__dirname + "/html"))
app.use(express.urlencoded({extended: false}));
app.engine(
'hbs',
expressHbs.engine({
layoutsDir: __dirname + "/views/layouts",
partialsDir: __dirname + "/views/partials",
defaultLayout: "layouts",
extname: "hbs",
runtimeOptions:{
allowProtoPropertiesByDefault: true,
},
helpers:{
showDate: (date) =>{
return date.toLocaleDateString('en-US', {
year: "numeric",
month: "long",
day: "numeric",
});
}
},
})
);
app.set("view engine", "hbs");
app.get("/", (req, res) => res.redirect("/blogs"));
app.use("/blogs", require("./routes/blogRouter"));
app.get("/createTables", (req, res) => {
let models = require("./models");
models.sequelize.sync().then(() => {
res.send("Table created!");
});
});
app.listen(port, () => console.log(`Example app listening to port ${port}`));