DEV Community

Cover image for What is the difference between Controllers and Services in Node REST API's?

What is the difference between Controllers and Services in Node REST API's?

Corey Cleary on February 12, 2019

Originally published at coreycleary.me. This is a cross-post from my content blog. I publish new content every week or two, and you can sign up to ...
Collapse
 
thespiciestdev profile image
James Allen

@ccleary00 , have you tried NestJS? With its dependency injection your controller is totally unaware of whether the user or email service is an AWS service, in-memory service, stub service, etc. The controller just knows there will be an addUser method to the user service and what that service does under the hood, the controller doesn't know or care.

Anything to help separate concerns (and reuse and testing!)

Collapse
 
ccleary00 profile image
Corey Cleary

I haven't tried it out yet, but will play around with it soon (I keep seeing it mentioned lately)

Collapse
 
idrisrampurawala profile image
Idris Rampurawala

Very well written!

Collapse
 
larswaechter profile image
Lars Wächter

Very good, thanks!