I like to look at route/index.js as a single source of contact with all the routes. You could have 100s of routes with there own query strings etc and all of it stays in one place and app.js stays clean. Whereas when we combine it with the controllers it becomes hard to track (for me). But ultimately all these patterns are there to make things easier. If combining them works for you and your organization than there is no reason to consider seperating them 🌟
The way we deal with it is, we have a route per "type" or "base path" - e.g. consider an api with /api/foo and /api/bar. Then we could have a folder routes with a file foo.js and bar.js - each with the routes belonging to those, rather than having one single file with all routes that would eventually become very, very long as the api grew.
Amazing! I have to admit I had no intention or expectation of my comment leading to you editing the initial post. How amazing it is that we can discuss, share and learn from each other!
I like to look at route/index.js as a single source of contact with all the routes. You could have 100s of routes with there own query strings etc and all of it stays in one place and app.js stays clean. Whereas when we combine it with the controllers it becomes hard to track (for me). But ultimately all these patterns are there to make things easier. If combining them works for you and your organization than there is no reason to consider seperating them 🌟
Alright, I get your point!
The way we deal with it is, we have a route per "type" or "base path" - e.g. consider an api with
/api/foo
and/api/bar
. Then we could have a folderroutes
with a filefoo.js
andbar.js
- each with the routes belonging to those, rather than having one single file with all routes that would eventually become very, very long as the api grew.This makes sense to me now!
I think your suggested way may be better than what I've done in this article. I'll update it.
Thanks for sharing! :)
Amazing! I have to admit I had no intention or expectation of my comment leading to you editing the initial post. How amazing it is that we can discuss, share and learn from each other!
Indeed! :D