Skip to main content
Version: 2.6.0

Configuration file


Low level configuration and options can be defined modifying the mocks.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 plugins extra options.



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

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

module.exports = {
babelRegister: true,
addPlugins: [FooPlugin],
addRoutesHandlers: [FooRoutesHandler],
options: {
path: "custom-mocks-folder",
port: 3200,
mock: "foo-mock",
cli: false,
cors: true,
corsPreFlight: false,


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

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

module.exports = (config) => {
config.options.mock = "foo-mock";
return config;


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

// mocks.config.js
const getMockAsyncMethod = require("./getMockAsync");

module.exports = async (config) => {
config.options.mock = await getMockAsyncMethod();
return config;
// mocks.config.js
const getAsyncConfig = require("./getAsyncConfig");

module.exports = () => {
return getAsyncConfig()
.then(config => {
return config;