DEV Community

Discussion on: ExpressJS Project Structure

Collapse
 
hailomym profile image
HailoMYM

Something that I found useful is to have a deeper layer inside constrollers that I usually call services.

What controllers do is to receive the request from the client, "manage" the data and pass it to the required services. The idea of services is to "do" the task without depending on the package or framework that is used.

So a controller receives the req object, extract the required info like the body or params and pass plain javascript objects to the services that does not care if we are using express or other tool.
You can find more about this structure in the following articule coreycleary.me/project-structure-f...

Collapse
 
brianemilius profile image
Brian Emilius

Hi @hailomym 👋

I 100% agree with the deeper layer. Sometimes I call it services, sometimes I have it split down even further into ORM and other services / business logic.

When I get to the MVC part of this project, I am going to dive into the reasons for this choice, so hang tight 😄