Project structure
We are using Node.js in the middle-layer. Node.js code needs to be properly structured to maintain and reuse it in future. In this section, we are going to divide our application in a way to achieve high cohesion and less code coupling.
Here is our project structure:
Controllers
Models
Node_modules
View
app.js
filePackage.json
The code base is separated in models (code dealing with database), controllers (code dealing with models and view), and view (frontend of the application). This kind of code division is proven to be more robust and highly cohesive.
Controllers generally take care of routes and communication between models and views. They accept the request from the view, transfers it to the model, and then updates the view when it receives the data from the the models.
Models contain code dealing with database operation. Models are not exposed to the outside world, that is, the frontend cannot call model code directly. Every request must go through controllers to models and...