Book Image

Web Development with MongoDB and Node.js

By : Jason Krol
Book Image

Web Development with MongoDB and Node.js

By: Jason Krol

Overview of this book

Table of Contents (19 chapters)
Web Development with MongoDB and Node.js
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
12
Popular Node.js Web Frameworks
Index

Rendering the views


Let's take a minute to do a quick recap and see what we've done up to this point. So far, we have:

  • Created index.handlebars and image.handlebars—the views for the two main pages of the application

  • Created layouts/main.handelbars—the main layout file for every page in the application

  • Created partials/comments.handlebars, popular.handlebars, and stats.handlebars

  • Created a global timeago Handlebars helper

So far so good; however, none of these views actually do anything, receive any ViewModels, or even appear when you run the application! Let's make a few quick minor modifications to our controllers to get our views to render properly.

Open /controllers/home.js so that you can edit the home controller module. Update the contents of that file so that it looks identical to the following block of code:

module.exports = {
    index: function(req, res) {
        res.render('index');
    }
};

Instead of performing res.send, which just sends a simple response, we are calling res.render...