# Wiring MongoDB into Express

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.

![Cheat sheet: Wiring MongoDB into Express](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/f3a4b0f656344421ae101f3c4d0c680f.webp)

- Category: Node.js
- Level: Journeyman
- Tags: 404 Not Found, Connection Pool, Dependency Injection (oop), Error-Handling Middleware, mongodb, nodejs, rest-api, Signal (unix)
- Author: Gregor Dzierzon
- Updated: November 23, 2026

Source: https://www.ask-codey.com/cheat-sheets/node-mongodb-in-express-cheat-sheet
