Interactive CLI animation

Mocks Server

Node.js mock server

Route variants

Define different responses for the same route, and group them into different mocks. Ensure that your API client is ready to handle all cases both in development and testing phases.

Multiple formats

Define routes and mocks using json files or JavaScript files. Babel is also supported, so ESM modules and TypeScript can also be used. Define responses using plain objects, or even Express middlewares. Hot reload changes the responses in real time once files are changed.

Easy to use

Change the current mock and other settings while the server is running using the interactive CLI or the admin REST API. Integrations with other tools are also available.

Friendly

Install and start it in seconds. Read get started to know how it works and you will be adding your own routes in minutes.

Modify the configuration file, or use the interactive CLI or the admin REST API for changing settings while it is running.

There are also available packages for integrating the Mocks Server with other development tools. @mocks-server/cypress-commands allows to easily control the mock server from Cypress. Read the Cypress integration chapter for further info

Flexible and maintainable

Define route variants for HTTP responses in JSON files, or as JavaScript objects.

Express middlewares can be also used for more complex scenarios.

Group route variants into different mocks.
Mocks can be created extending from another ones, so you can modify or add new routes to the main mock, and the rest of mocks will inherit them.

If this is not enough, you can even add your own route handlers to add more formats for defining route variants.
// mocks/routes/users.json
[
{
"id": "get-user",
"url": "/api/user/:id",
"method": "GET",
"variants": [
{
"id": "success",
"response": {
"status": 200,
"body": { "id": 1, "name": "John Doe"}
}
},
{
"id": "not-found",
"response": {
"status": 404
}
}
]
}
]

Pluggable

Plugins can be easily installed from NPM or developed.

Plugins can do a lot of things in Mocks Server. Even some very important built-in internal pieces are, in fact, plugins. So, you could use plugins to provide more interfaces, add more routes handlers, add express routers to the server, etc.

Read also the programmatic usage chapter to learn how to use Mocks Server from your own program.
class MyPlugin {
constructor(mocksServer) {
mocksServer.addSetting({
name: "traceMocks",
type: "boolean",
description: "Trace mocks changes",
default: true
});
mocksServer.onChangeMocks(this._onChangeMocks.bind(this))
}
// ...
}

Upcoming features

Administration web user interface, Chrome extension, Proxy fallback, Web Sockets, etc.

Check the GitHub project to stay up to date on what we are working.

Give it a star on GitHub