Skip to main content
Version: 1.9.0

Configuration file

Options

Configuration and options can be defined creating a mocks-server.config.js file in the root folder of your project (a custom file path can be defined using the configFile low level configuration property).

The first level properties returned by this configuration file will be interpreted as low level configuration properties.

Properties returned inside the options object will be considered as main options or plugin extra options.

Formats

Object

The configuration file can export an object containing configuration and options:

// mocks-server.config.js
const FooPlugin = require("mocks-server-plugin-foo");

module.exports = {
addPlugins: [FooPlugin],
options: {
path: "custom-mocks-folder",
port: 3200,
behavior: "foo-behavior",
cli: false
}
};

Function

The configuration file can export a function. The function receives previously defined configuration (from previous config methods) that can be modified.

// mocks-server.config.js
const FooPlugin = require("mocks-server-plugin-foo");

module.exports = config => {
config.plugins.push(FooPlugin);
config.options.behavior = "foo-behavior";
return config;
};

Async

The configuration file can also export an async function, or a function returning a Promise:

// mocks-server.config.js
const getAsyncBehavior = require("./getAsyncBehavior");

module.exports = async config => {
const behavior = await getAsyncBehavior();
config.options.behavior = behavior;
return config;
};
// mocks-server.config.js
const getAsyncConfig = require("./getAsyncConfig");

module.exports = () => {
return getAsyncConfig()
.then(config => {
console.log(config);
return Promise.resolve(config);
});
};