Skip to main content
Version: 3.0.0

Options

Options

Here are described the Mocks Server core options. To know how to define them using different methods, please read the previous chapter.

  • config.allowUnknownArguments (Boolean): If true, it allows to define unknown command line arguments. Default is false. This option can be defined only programmatically, using configuration file or environment variables.
  • config.fileSearchPlaces (Array of Strings): Paths to search for the configuration file. Default is described in the configuration methods chapter. This option can be defined only programmatically or using environment variables.
  • config.readArguments (Boolean): If false, it disables the ability of defining options using command line arguments. Default is true. This option can be defined only programmatically, using configuration file or environment variables.
  • config.readEnvironment (Boolean): If false, it disables the ability of defining options using environment variables. Default is true. This option can be defined only programmatically.
  • config.readFile (Boolean): If false, it disables the ability of reading configuration file. Default is true. This option can be defined only programmatically, using configuration file or environment variables.
  • files.path (String): Path to the folder containing mocks and routes to be used by the server. Default is /mocks
  • files.watch (Boolean): Watch mocks folder and restart server on changes. Default is true.
  • files.babelRegister.enabled (Boolean): Enables Babel compilation for files inside the mocks folder.
  • files.babelRegister.options (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.
  • log (String): Logs level. Can be one of silly, debug, verbose, info, warn or error.
  • mocks.delay (Number): Responses delay time in milliseconds. This is a global setting that can be overridden for specific routes or route variants using their options.
  • mocks.selected (String): Mock to use when the server is started.
  • plugins.register: (Array of Plugin): Array of Plugins, defined as described in the plugins chapter.
  • routesHandlers (Array of RouteHandler): Array of RouteHandler to be added.
  • server.cors.enabled (Boolean): Built-in CORS middleware. Default is true. Use false to disable it.
  • server.cors.options (Object): Options for the built-in CORS middleware. By default, it sets the preflightContinue property as false, which means that Mocks Server will respond to all OPTIONS requests with a 204 status and correspondent CORS headers. If you want to handle OPTIONS requests by yourself, you should set that property to true.
  • server.host (String): Host for the server. Default is 0.0.0.0 (Listen to any local host).
  • server.jsonBodyParser.enabled (Boolean): If false, it disables the json body-parser built-in Express middleware. Default is true.
  • server.jsonBodyParser.options (Object): Options for the json body-parser built-in Express middleware.
  • server.port (Number): Port number for Mocks Server to be listening at. Default is 3100.
  • server.urlEncodedBodyParser.enabled (Boolean): If false, it disables the urlencoded body-parser built-in Express middleware. Default is true.
  • server.urlEncodedBodyParser.options (Object): Options for the urlencoded body-parser built-in Express middleware.

Plugins 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 core options. Note that all plugins options must be defined under the plugins namespace, and each plugin options must be defined under its own plugin id namespace (plugins.[plugin-id].[option])

  • plugins.inquirerCli.enabled (Boolean): Start interactive CLI plugin or not. Default is true.
  • plugins.inquirerCli.emojis (Boolean): Defines whether the inquirer CLI uses emojis or not. Default is true.
  • plugins.adminApi.path (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.