Mountebank is an open-source, cross-platform, multi-protocol test double tool designed to mock services over the wire. It enables developers to create configurable mock API endpoints for various protocols like HTTP, HTTPS, TCP, and SMTP. Mountebank primarily operates by creating "imposters" that listen on specified ports, responding to requests based on defined "stubs" which include predicates (conditions) and responses. This approach allows for isolated and repeatable testing of applications, reducing dependencies on external services and improving development efficiency. The project recently transitioned to a community-driven effort under the `mountebank-testing` GitHub organization, with the npm package name changing from `mountebank` to `@mbtest/mountebank`. It maintains a consistent release cadence, with several updates in the past year (v2.9.1 to v2.9.4). Key differentiators include its multi-protocol support, a powerful REST API for dynamic configuration, and the ability to extend functionality through JavaScript injection.
npm install mountebankVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to install Mountebank globally, start the `mb` server, programmatically create a simple HTTP GET imposter via its REST API, and then verify the mock response.
Update your `package.json` dependency to `"@mbtest/mountebank": "^2.9.x"` and reinstall. For global installs, use `npm install -g @mbtest/mountebank`.
Upgrade your Node.js environment to version 20 or higher. For Docker deployments, use images based on Node 24 or later.
When starting Mountebank, either via CLI or programmatically, ensure the `--allowInjection` flag is included: `mb --allowInjection` or `mb.create({ allowInjection: true })` if using a client library.To persist configurations, use `mb --configfile your-imposters.json` on startup, or `mb --datadir /path/to/data` to persist all changes automatically to disk. Programmatically, ensure imposters are recreated after a server restart.
Change the conflicting port in your Mountebank configuration, or stop the other application using that port. For imposters, specify a different `port` in your imposter configuration. For the admin API, use `mb --port <newPort>`.
Restart Mountebank with the `--allowInjection` command-line flag: `mb --allowInjection`.
Upgrade npm to version 3 or higher (`npm install -g npm@latest`). If stuck on npm v2, a workaround involves adding mountebank's top-level dependencies to your `package.json` and deleting `node_modules/mountebank/node_modules` between `npm install` and `npm shrinkwrap`.