Database Code in One Place

Database Code in One Place: Keeping Database Code in One Place, Wiring MongoDB into Express.

Updated

  1. Keeping Database Code in One Place (Journeyman): A repository module is the one file in an API that talks to MongoDB, with functions such as create and get that give back plain objects whose id is text, so the routes never need to know how the data is stored.
  2. Wiring MongoDB into Express (Journeyman): An Express API connects to MongoDB once when the server starts, hands the database to createApp(db), answers 404 when the repository finds no workout, lets a failed database call reach the error-handling middleware, and closes the connection when Ctrl+C stops it.