Book Image

Node Web Development - Second Edition

By : David Herron
Book Image

Node Web Development - Second Edition

By: David Herron

Overview of this book

Table of Contents (17 chapters)
Node Web Development Second Edition
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Express and the MVC paradigm


Express doesn't follow a pure model-view-controller (MVC) structure, but the blank application created by the express command line tool provides you with two MVC aspects. These are stated as follows:

  • The views directory contains template files, hence controls the data display, and corresponds to the view

  • The routes directory handles requests on URLs, hence sends commands inside the application, and corresponds to the controller.

This leaves one wondering how to handle code implementing the model. The role of the model is to hold the application data, changing the data as instructed by the controller, and supplying the data requested by the view.

At a minimum, the model code should be in a separate module from the controller code. That's because, ideally, the model and controller code should be as independent from each other as possible.

The approach we'll use in developing the Notes application is to create a models directory as a sibling of views and routes. The...