Facebook Pixel

When should I move to the module pattern?

For medium to large apps. Group each feature into a module (src/modules/users/ with router, controller, service, model, validations). Mount modules in app.js. For tiny apps, a flat structure is fine.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Express API Structure Roadmap: From Spaghetti to Modular

Start with app.js, add a routes folder, mount routers in app.js, add controllers, add a services layer, add middlewares, add validations, add models and utils folders, add a config folder, version the API, and move to the module pattern for large apps.

When you have more than ~10 routes. Move them into a routes/ folder with one file per feature. Mount each router in app.js with app.use('/path', router). app.js becomes thin.

When controllers get long. Move logic into services/. Controllers parse the request, call a service, send the response. Services do the work and are reusable and testable without an HTTP context.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.