I'm new to Express and programming in general.
If you follow this book you learn to create a single Router() which maps all the routes to all the controllers. You end up having:
app.use('/users', users) // mounts a Router()
app.use('/posts', posts) // mounts another Router()
It seems that Express prefers to have a seperate Router mounted for each controller. Have I got it right?
Multi-routers allows to separate your routes in modules. It avoids to have a big file with all routes. For example, if you take
app.use('/users', users), your users.js file will contain all routes associated to users.
Personally, I work on a project with mongoose (http://mongoosejs.com/) which use this architecture :
express/ index.js <- Main file to configure express router with adding middlewares, etc. routes.js <- All your routes are required in this file entities/ users/ users.model.js <- Model of the user users.controller.js <- Controller associated to the model. Any route call a function of the controller users.routes.js <- All routes for users projects/ projects.model.js projects.controller.js projects.routes.js
With a multi-routers architecture, you will gain scalability and readability. And separation between callbacks and routes avoid to pollute your router with controllers code.