Implementing the MVC pattern
The Express framework is pattern agnostic, which means it doesn't support any predefined syntax or structure as do some other web frameworks. Applying the MVC pattern to your Express application means that you can create specific folders where you place your JavaScript files in a certain logical order. All those files are basically CommonJS modules that function as logical units. For instance, models will be CommonJS modules containing a definition of Mongoose models placed in the models
folder, views will be HTML or other template files placed in the views
folder, and controllers will be CommonJS modules with functional methods placed in the controllers
folder. To illustrate this better, it's time to discuss the different types of an application structure.
Application folder structure
We previously discussed better practices while developing a real application, where we recommended the use of the package.json
file over directly installing your modules. However...