# mongodb-memory-server: your test install downloads a mongod binary, and the default is 8.2.6 while the example pins 4.2.8

> A TypeScript package that starts a real MongoDB server inside a Node test run, holding data in memory so integration tests stay isolated. It reaches out to a MongoDB download host on install unless you pick the core package, resolves your Linux distribution through four fallbacks, and binds to loopback by default with an option that will bind every interface.

**typegoose/mongodb-memory-server** — Manage & spin up mongodb server binaries with zero(or slight) configuration for tests.

- Repository: https://github.com/typegoose/mongodb-memory-server
- Website: https://typegoose.github.io/mongodb-memory-server/
- Stars: 2,852 · Forks: 191
- Language: TypeScript
- License: MIT
- Published: 2026-09-28 · Updated: 2026-09-28 · Language: en
- Canonical page: https://hysenlabs.com/projects/typegoose-mongodb-memory-server

## Your npm install downloads a mongod binary from a MongoDB host

The first thing to understand about this package is that installing it is a network operation. On install the package downloads the latest MongoDB binaries and saves them to a cache folder, pulling from the MongoDB download host, choosing the build for your operating system, with links given for the available Linux distributions, macOS and Windows builds. The stated purpose is that a fresh server process takes about seven megabytes of memory and holds its data in memory by default, so the cost of running it per test suite is small. But the cost of getting it is a download of a database server binary during npm install, which is exactly the behaviour that breaks sealed build environments, air-gapped CI and some registry mirrors. The escape hatch is a separate package, described next.

## Three packages that differ only in whether they download on install

The installation section lists three package names grouped into two behaviours. The auto-download group is the main package and the global variants, which fetch binaries when npm installs them. The no-download group is the core package, which skips the download on its postinstall hook. Then comes the sentence that decides how to read the rest of the documentation: choose any package, because they are the same, and they differ only in the default configuration, which you may override. So the three names are one codebase with two defaults flipped, and the choice is a policy decision about your build pipeline rather than a feature decision. The runtime behaviour has its own switch as well: if the binary cannot be found when a new instance starts, it is fetched again provided a runtime download option is truthy, which is why the first run can be slow and later runs are fast.

## Linux distribution detection has four fallbacks and ends in manual specification

The requirements section is unusually specific about Linux, because the download host publishes different builds per distribution and the package has to guess which one you want. Four options are offered and you need one of them: the release core package installed, or anything that provides the release command; a compliant os-release file in the etc directory; a compliant release file in etc that does not include lsb; or manually specifying which version and system to use. The ordering implies the package tries each in turn, which is the behaviour you would expect from a tool that has to work across Debian derivatives, Red Hat derivatives and SUSE. Two more requirements sit alongside: the curl library, version four or three on older distributions, and a note that this will probably only be an issue on slim container images. That last clause is the practical warning, since a slim image is exactly where the release files tend to be missing.

## The default binary is 8.2.6 and the documented example pins 4.2.8

The configuration section states the default plainly: the version 8.2.6 build for your operating system will be downloaded. It then shows how to override that with two environment variables, one pointing at a download address and one naming the version:

```sh
export MONGOMS_DOWNLOAD_URL=https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.8.tgz
export MONGOMS_VERSION=4.2.8
```

The example is the interesting part, because it is several major versions behind the default it is meant to illustrate. It also pins a specific distribution build from an older Ubuntu release, so copying it verbatim gets you a Linux tarball on a machine that may not be that distribution, and a server several majors older than the one the package would have chosen. The variables themselves are the documented interface, and the configuration documentation on the project site is linked for the full set of options, including the runtime download switch that decides whether a missing binary is fetched or an error is raised.

## The address option defaults to loopback and can be set to bind everything

The options block for a normal server lists the settings that matter for a test harness, and one of them deserves attention. The port option says that by default any free port is chosen. The address option defaults to the loopback address, and its comment states that to bind to all IP addresses you set it to a value combining the IPv6 and IPv4 wildcards. That is a one line change with a real consequence: a mongod listening on every interface is reachable from anything that can route to the host, and a test database is still a database with whatever data your fixtures put in it. The remaining options in the block are more conventional: a database name defaulting to an empty string, a data path defaulting to a temporary directory, a replica set name defaulting to none, and an arguments array. The block itself is cut off partway through that last line, so the option list is not complete in the README.

## The storage engine default depends on which mongod version you get

One option has a version-dependent default, which is unusual enough to be worth isolating. The storage engine option defaults to the test-oriented ephemeral engine, except on one version where the default is the full write-ahead logging engine instead. The block names the exception as MongoDB 7.0.0 and lists the two available engines as the ephemeral test engine and the write-ahead logging one. The consequence is that the same configuration object can behave differently depending on which binary your machine resolved, and since the default binary version is itself configurable, a test suite can change storage semantics by changing an environment variable. The replica set entry point is the other place version matters: a replica set can be started with a member count, and the example creates one with four members. The snippet showing how to read its connection string stops mid-expression.

## A monorepo whose install step wires git hooks and whose table of contents is generated

The repository is a monorepo whose root manifest is private and pinned at version zero, with a workspace glob covering the packages directory, so the three published names come from inside that directory rather than from the root. Two details in the tooling are more revealing than the package list. The root postinstall script runs husky, which means a plain development install of the repository installs its own git hooks. And the README's table of contents sits inside comments marked as generated by a documentation table of contents tool, with lint-staged configured to regenerate that README on every commit alongside running the linter with fixes on the package sources. Commit messages are linted too, with commitlint and the conventional configuration. Documentation is built with typedoc into a website directory that has its own npm prefix and its own start script.

## Conclusion

mongodb-memory-server fits a Node project whose integration tests need real MongoDB semantics, including replica set behaviour, without a shared database. Four things to know before it enters a build. The default install downloads a server binary from MongoDB's own download host, so the package's install step has network access and a cache directory, and the core package is the variant that skips it. The binary it wants is 8.2.6 while the documented override example pins 4.2.8, so copying that example moves you several major versions back. Distribution detection on Linux has four fallbacks ending in manual specification, which is what slim container images usually need. And the address option can bind the server to every interface, so keep the loopback default unless you understand why you are changing it.

## FAQ

### How do I install mongodb-memory-server?

Add one of its three packages to your project. Node 20.19.0 or newer is required, plus TypeScript 5.9 if you use it, and on Linux either the release core tooling, a compliant os-release file, a compliant etc release file, or a manual specification of version and system. The curl library is also required, which usually only matters on slim images.

### What is mongodb-memory-server?

A TypeScript package that starts a real MongoDB server from inside Node for testing or mocking, holding the data in memory by default, with a fresh process taking about seven megabytes. Each instance creates and starts its own server on a free port, so several can run at once, and the servers shut down when your script ends or you call stop.

### Does mongodb-memory-server download MongoDB during npm install?

Yes by default. The main package and the global variants download the latest MongoDB binaries on install and cache them, while mongodb-memory-server-core skips the download on its postinstall hook. At runtime a missing binary is downloaded again if the runtime download option is truthy, so the first run can take a while.

### Which MongoDB version does mongodb-memory-server use by default?

Version 8.2.6 for your operating system. The documented override example sets the download address to a 4.2.8 tarball built for an older Ubuntu release and sets the version variable to 4.2.8, so copying the example moves you several major versions behind the default.

### Can mongodb-memory-server listen on all network interfaces?

It can, but not by default. The address option defaults to the loopback address, and its comment says that to bind to all IP addresses you set it to a value combining the IPv6 and IPv4 wildcards. The port option already defaults to any free port.

## Sources

- [License: MIT](https://github.com/typegoose/mongodb-memory-server/blob/master/LICENSE)
- [Project website](https://typegoose.github.io/mongodb-memory-server/)
- [README](https://github.com/typegoose/mongodb-memory-server/blob/master/README.md)
- [Releases](https://github.com/typegoose/mongodb-memory-server/releases)
- [typegoose/mongodb-memory-server on GitHub](https://github.com/typegoose/mongodb-memory-server)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/typegoose-mongodb-memory-server
