re: How do you separate and organize your Express.JS files? VIEW POST

FULL DISCUSSION
 

Lack of a common project structure in the Node-world is very frustrating. Every team I've been on has done it differently, but I've combined what I learned from each project and have been able to come up with a structure I feel is pretty sound.

I structure mine like so:

  • controllers
  • db/DAL
  • routes (each endpoint)
  • services
  • tests
  • utils app.js (the entrypoint)

By adding a "services" concept, you can put a lot of your business logic there, and leave the controllers to simply take the HTTP request (req object in Express) and orchestrate the services. This makes your business logic much easier to test and keeps your controllers thin.

I wrote about this in much more detail here - Project structure for an Express REST API when there is no "standard way" and explain not only what the structure should look like, but what types of logic go there.

 

Thank you! Your article is very good. That helped me a lot :)

code of conduct - report abuse