mongodb-memory-server
noun
say it: “MAHNG-goh-dee-BEE MEM-uh-ree SUR-ver” /ˈmɑŋɡoʊˌdiˈbi ˈmɛməri ˈsɝvər/
An npm package that starts a temporary MongoDB server for tests and removes it when they finish.
What is mongodb-memory-server?
mongodb-memory-server is an npm package that starts a real, throwaway MongoDB server for your tests, in a temporary folder on a free port, and stops it afterward. Tests get a real database without touching yours.
import { MongoMemoryServer } from "mongodb-memory-server";
const mongo = await MongoMemoryServer.create();
const uri = mongo.getUri(); // mongodb://127.0.0.1:53412/
// ...connect with uri and run the tests...
await mongo.stop();
In a sentence
- “On its first run, mongodb-memory-server downloads MongoDB, so that test run takes longer.”
- “The workout log's tests use mongodb-memory-server, so each run starts with an empty database.”
Level: Journeyman · More Node.js terms at this level
Updated