Model-Routes-Controllers-Services Directory Structure
suggest change├───models
│ ├───user.model.js
├───routes
│ ├───user.routes.js
├───services
│ ├───user.service.js
├───controllers
│ ├───user.controller.js
For modular code structure the logic should be divided into these directories and files.
Models - The schema definition of the Model
Routes map URLs to controller functions.
Controllers validate the request and send the response.
Services run the database queries and return objects or throw.
The split adds files. Each piece stays separate and easier to change.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents