What should app.js contain in a large Express app?
Only: create the app, apply global middlewares (json, cors, helmet), mount routers with app.use, and register the error handler. Everything else lives in feature folders. A thin app.js is a sign of a well-organized app.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Express Router Best Practices for Large Apps
One router per feature (routes/auth.js, routes/users.js, etc.). Mount each under a path in app.js. Apply per-router middlewares. Keep public routes outside auth routers. Keep app.js thin: only global middlewares, router mounts, and the error handler.
Mount routers under /api/v1, /api/v2, etc. Each version has its own router. Bump the version on breaking changes. Non-breaking changes (adding fields) do not need a new version.
Use router.use(middleware) at the top of the router file. Every route in the router now runs that middleware. Useful for auth and role checks across a feature.
Still have questions?
Browse all our FAQs or reach out to our support team
