Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Web Development with MongoDB and Node.js

You're reading from   Web Development with MongoDB and Node.js Build an interactive and full-featured web application from scratch using Node.js and MongoDB

Arrow left icon
Product type Paperback
Published in Sep 2014
Publisher Packt
ISBN-13 9781783987306
Length 294 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Jason Krol Jason Krol
Author Profile Icon Jason Krol
Jason Krol
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Web Development with MongoDB and Node.js
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Welcome to JavaScript in the Full Stack FREE CHAPTER 2. Getting Up and Running 3. Node and MongoDB Basics 4. Writing an Express.js Server 5. Dynamic HTML with Handlebars 6. Controllers and View Models 7. Persisting Data with MongoDB 8. Creating a RESTful API 9. Testing Your Code 10. Deploying with Cloud-based Services 11. Single Page Applications with Popular Frontend Frameworks 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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images