Skip to content

Commit

Permalink
express-handlebars config
Browse files Browse the repository at this point in the history
  • Loading branch information
chhinsras committed May 17, 2018
1 parent 2d66e8a commit e79158f
Show file tree
Hide file tree
Showing 9 changed files with 423 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
package-lock.json
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
# vidjot
# vidjot

### init git repository

### project dependencies

```
1. npm install -g nodemon (auto restart server)
2. npm install --save express
3. npm install --save express-handlebar (template engine)
```

### Create Handlebar

```
1. Create Middleware
const exphbs = require("express-handlebars");
// express handlebar middleware
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
2. Create Views Folder
- views/index.handlebars (Index Section View)
- views/about.handlebars (About Section View)
- views/layouts/main.handlebars (HTML Body View)
- views/partials/_navbar.handlebars (Partial Body / Navgiation Bar)
```
21 changes: 21 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const express = require("express");
const exphbs = require("express-handlebars");
const app = express();

// express handlebar middleware
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");

// Index route
app.get("/", (req, res) => {
const title = "Vidjot Title";
res.render("index", { title });
});

// About route
app.get("/about", (req, res) => {
res.render("about");
});

const port = 5000;
app.listen(port, () => console.log(`Server running on port ${port}`));
Loading

0 comments on commit e79158f

Please sign in to comment.