Tag Archives: handlebars

01 Project – Node.js / Express / MongoDB – Part 11 – Rendering the views

None of these views we have created so far will do anything unless we make a few modifications to our controllers to get our views to render properly.

Open /controllers/home.js and update the contents to look identical to the code shown below:

module.exports = {
  index: function(req, res) {

Continue reading

01 Project – Node.js / Express / MongoDB – Part 10 – Creating {{ timestamp }} global helper

The global helper that we are going to create will be used to format a timestamp. It will display a date according to how long ago the event occurred. We will use this for things such as comments and image timestamps.

First, we need to update our server/configure.js module. We are going to add a section to define our helpers:

app.engine('handlebars', exphbs.create({
    defaultLayout: 'main',
    layoutsDir: app.get('views') + '/layouts',
    partialsDir: [app.get('views') + '/partials'],
    helpers: {
      timeago: function(timestamp) {
        return moment(timestamp).startOf('minute').fromNow();

Continue reading

01 Project – Node.js / Express / MongoDB – Part 08 – Creating the main.handlebars file layout

When you build a website you would want to have a layout (template) used by every page. This layout should contain a header with title, logo etc, a navigation bar (if the developer needs a navigation bar), and a footer to contain the copyright information and maybe other information. Handlebars helps you with this matter!

Let’s create a layout file for our application by creating a new file named main.handlebars within the views/layouts folder. Insert the following code in it:

<html lang="en">

   Continue reading