Version: 2.3.0

Options

Methods#

This chapter describes all available configuration properties and options. There are multiple methods for defining configuration and options.

When the same option is defined using multiple methods, the priority is (from lower to higher):

Main options#

These options can be defined using command line arguments, the configuration file, and can be changed while the server is running using the settings methods.

  • path (String): Path to the folder containing mocks and routes to be used by the server. Default is /mocks
  • port (Number): Port number for Mocks Server to be listening at. Default is 3100.
  • host (String): Host for the server. Default is 0.0.0.0 (Listen to any local host).
  • log (String): Logs level. Can be one of silly, debug, verbose, info, warn or error.
  • watch (String): Watch mocks folder and restart server on changes. Default is true. Use false to disable it.
  • mock (String): Mock to use when the server is started.
  • delay (Number): Responses delay time in milliseconds.
  • cors (Boolean): Built-in CORS middleware. Default is true. Use false to disable it.
  • corsPreFlight (Boolean): Built-in CORS pre-flight middleware. If enabled, Mocks Server will respond to all OPTIONS requests with a 204 status and correspondent CORS headers. It requires the cors option to be enabled also. Default is true. Use false to disable it (if you want to handle OPTIONS requests by yourself, for example).

Plugins extra options#

Each plugin can add its own options when it is installed. These options can also be defined and changed using the same methods as the main options.

  • cli (String): Start interactive CLI. Default is true. Use false to disable it.
  • adminApiPath (String): Path for the administration REST API. Default is /admin. You should change it only in case there is any conflict with the api you are mocking.
note

These extra options are added by the @mocks-server/plugin-admin-api and the @mocks-server/plugin-inquirer-cli plugins, which are both included in the Mocks Server main distribution.

For another plugins options, please refer to their own documentation.

Low level configuration#

This options can't be modified while the server is running, and can be defined only using the configuration file or programmatically.

  • babelRegister (Boolean): Enables Babel compilation for files inside the mocks folder.
  • babelRegisterOptions (Object): Options for @babel/register when babelRegister is enabled. Properties in this object are passed directly to @babel/register as options, so refer to its documentation for further info. You can also see some usage examples in the "using Babel" section of this docs.
  • plugins (Array of Plugin): Array of Plugins, defined as described in the plugins chapter.
  • addPlugins (Array of Plugin): Array of Plugins to be added. This option does not overwrite previously defined plugins.
  • addRoutesHandlers (Array of RouteHandler): Array of RouteHandler to be added. This option does not overwrite previously defined plugins.
  • configFile (String): Custom path for the configuration file. If relative, it will be resolved from current working directory. Default is mocks.config.js.
  • onlyProgrammaticOptions (Boolean): If true, it disables both command line arguments and configuration file.
  • disableCommandLineArguments (Boolean) If true, all command line arguments defining options will be ignored.
  • disableConfigFile (Boolean): If true, the configuration file will be ignored.