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

This book is designed for developers of any skill level that want to get up and running using Node.js and MongoDB to build full featured web applications. A basic understanding of JavaScript and HTML is the only requirement for this book.
Table of Contents (14 chapters)
12
12. Popular Node.js Web Frameworks
13
Index

Chapter 6. Controllers and View Models

Up until this point, the controllers we wrote for our application have been extremely basic. They were started with a simple task of sending text responses to the client. In the previous chapter, we updated the controllers so that they render an HTML view and send the HTML code to the client (instead of simple text). The primary job of a controller is to act as the logic that makes all of the necessary decisions to properly render a response to the client. In our case, this means retrieving and/or generating the data necessary for a page to appear complete.

In this chapter, we will:

  • Modify the controllers so that they generate a data model and pass it to a view
  • Include logic to support uploading and to save image files
  • Update the controllers to actually render dynamic HTML
  • Include helpers for the partials that generate the website statistics
  • Iterate on the UI to include improved usability via jQuery