Book Image

Node.js By Example

Book Image

Node.js By Example

Overview of this book

Table of Contents (18 chapters)
Node.js By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The Model-View-Controller pattern


It's always difficult to start a new project or the implementation of a new feature. We just don't know how to structure our code, what modules to write, and how they are going to communicate. In such cases, we often trust well-known practices—design patterns. Design patterns are reusable solutions to commonly occurring problems. For example, the Model-View-Controller pattern has proven to be one of the most effective patterns for web development due to its clear separation of the data, logic, and presentation layers. We will base our social network on a variation of this pattern. The traditional parts and their responsibilities are as follows:

  • Model: The Model is the part that stores the data or the state. It triggers an update on the View once there is a change.

  • View: The View is usually the part that the user can see. It is a direct representation of the data or the state of the Model.

  • Controller: The user interacts with the help of the Controller (sometimes...