Hello, I recently completed the URL Shortener Microservice challenge, during which I had to use Express and MongoDB to perform finds and inserts on a collection of submitted urls.
An architectural question arose when I had to use mongodb connection in two separate routes. The github repo showcases my take on this problem. Simply put, I connect to mongodb as soon as application starts and take it on faith that connection will be established before any requests to the server would be made.
I’m interested to know how different people solve similar problem, if there’s a programming pattern for it. I kinda want to overengineer this case, because I fail to see how my naive solution would translate to serious projects.
Github Link: https://github.com/mpontus/fcc-url-shortener-service
Project Link: https://pure-meadow-54992.herokuapp.com/