buisness logic in Node.js
You want to learn Node.js?
what a great choice but first to clarify things and make it easier let's understand the how does node works. I did the same for django if you interest give it a look.
First, node is a runtime environment so we use other package and framework to do help with the server, we will be using express.
MVC (Models Views Controllers) is the basic logic.
We try to separate the logic inside specific files in order to make things clear and organized
Models:
It contains the structure or a schema needed for the project, defining the type of data, relations and some type restriction…. , very beneficial when working with data base especially mongo db which comes with built in package (mongoose) that helps a lot.
Views:
Views are the files to manage url and routes, it defines the request type, call back functions and sometimes middleware.
If you have for example routes for authentication (login, register, logout) and others for posts (let's say we have a blog: create, getPosts, deletePost…).
It's very recommended to have each route in separated files! and so on you insert for each url a specific function that could controller.
Controllers:
Controllers were all the job is done! just kidding all the other parts as important as this one because unlike django, node gives more freedom to customize your project and API.
So in those functions we make our normal need (CRUD, authentication,…) and more! all this thanks to defined schema (models).
Bonus: remember to have place for middlewares 😉
Finally, all I was doing is theoretically speaking but understanding those topics is compulsory before digging deep into a future Node.js tutorial.
So stay tuned and give me feedbacks. 😍
No comments