Answer the question
In order to leave comments, you need to log in
Difference between service and controllers in node js ( express )?
Hello everyone, such a question. I met a lot of places and even wrote express code myself, in which service and controllers were in different folders, but I can’t fully grasp the essence of what service's is responsible for and what controller's is for ? Which of them is responsible for communicating with the database and so on? I hope I described clearly. Thank you ! :)
Answer the question
In order to leave comments, you need to log in
Service - we write all our logic in it. The service does not need to know anything about the request. It does not have access to either the Request or the Response.
Controller - receives a request and passes it to our service.
You can work with the database in the service, but more and more often I see that people use the “Repository” pattern, when all the logic of working with the database is put into it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question