DEV Community

loading...

Discussion on: 3 Steps To Architect A Express Server

Collapse
jha profile image
Amit jha Author

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 🌟

Collapse
hilleer profile image
Daniel Hillmann

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 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.

Thread Thread
jha profile image
Amit jha Author

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! :)

Thread Thread
hilleer profile image
Daniel Hillmann

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!

Thread Thread
jha profile image
Amit jha Author

Indeed! :D

Forem Open with the Forem app