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 is3100
.host
(String): Host for the server. Default is0.0.0.0
(Listen to any local host).log
(String): Logs level. Can be one ofsilly
,debug
,verbose
,info
,warn
orerror
.watch
(String): Watch mocks folder and restart server on changes. Default istrue
. Usefalse
to disable it.mock
(String): Mock to use when the server is started.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.cors
(Boolean): Built-in CORS middleware. Default istrue
. Usefalse
to disable it.corsPreFlight
(Boolean): Built-in CORS pre-flight middleware. If enabled, Mocks Server will respond to allOPTIONS
requests with a 204 status and correspondent CORS headers. It requires thecors
option to be enabled also. Default istrue
. Usefalse
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 istrue
. Usefalse
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
whenbabelRegister
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 ofPlugin
): Array of Plugins, defined as described in the plugins chapter.addPlugins
(Array ofPlugin
): Array of Plugins to be added. This option does not overwrite previously defined plugins.addRoutesHandlers
(Array ofRouteHandler
): Array ofRouteHandler
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 ismocks.config.js
.onlyProgrammaticOptions
(Boolean): Iftrue
, it disables both command line arguments and configuration file.disableCommandLineArguments
(Boolean) Iftrue
, all command line arguments defining options will be ignored.disableConfigFile
(Boolean): Iftrue
, the configuration file will be ignored.