# 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.

```javascript
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](https://www.ask-codey.com/glossary?category=nodejs&level=3)

Updated: November 19, 2026

Source: https://www.ask-codey.com/glossary/mongodb-memory-server
