You’ve structured yours the way I did mine the first time - I actually redid mine again from scratch after seeking feedback on Gitter…
Here was the exchange regarding my old one on gitter - I scrubbed their username so they don’t get pinged by me posting this :
username scrubbed May 22 21:29
@JacksonBates : It indeed is horrible You gotta modularize it.
The very first problem I see here is, every time your server receives a request, you server is going to open a new connection to the db port. Connecting to db is one of the most time consuming activities you can do.
What you need to do is cache the connection and reuse it afterward, instead of opening it over and over again.
Jackson Bates @JacksonBates May 22 21:38
so would I do that by opening the db connection outside of the various 'app.get’s?
I tried modularizing before, but I have trouble passing request and response objects around like that…I didn’t really feel like I learned modules from the Learnyounode lessons - are there other resources for learning modules you’d recommend?
username scrubbed May 22 21:48
- Separate your db logic from routing logic.
I’ll share some review comments in some time. I am at work right now.
You can take a look at FCC code base on github to see how they’re achieving modularity.
Jackson Bates @JacksonBates May 22 21:51
Thanks, I appreciate the pointers. I think I have enough to go on for now - but if there are glaring issues you haven’t mentioned yet and you have time to point them out later that would be great. You’ve been really helpful so far - cheers