Mock config server

CLI

Command Line Interface for mock-config-server

Run mock-config-server

mock-config-server

Starts a mock server in the current directory using a configuration file mock-server.config.(js|ts).

Usage

npx mock-config-server [options]

If the package is already installed, you can use the short command mcs

Options

OptionShortDescriptionDefault value
--baseUrl-bSpecify the base URL path from config. Must start with /./
--port-pSpecify the server port from config.31299
--staticPath-sSpecify the static assets path from the config. Must start with /.
--config-cSet path to the config file.mock-server.config.(js|ts)
--watch-wEnables server restart when config file changes.false
--help-hDisplay help for the command.
--version-vDisplay the mock-config-server version.

Create a mock-config-server template

mock-config-server init

Creates a mock configuration. It generates a mock-server.config.(js|ts) file with a config template and sample request examples in the current directory. An interactive flow lets you choose between TypeScript and JavaScript, select an API type (REST, GraphQL or both), and set basic server options like base URL, port and static path.

Usage

npx mock-config-server init

If the package is already installed, you can use the short command mcs

Options

OptionShortDescriptionDefault value
--baseUrl-bSpecify the base URL. Must start with /./
--port-pSpecify the server port.31299
--staticPath-sSpecify the static assets path. Must start with /.

Interactive flow

The command asks a few short questions:

? Would you like to use TypeScript? › No / Yes
? Choose API type (Use arrow keys)
 REST
  GraphQL
  Both
? Base URL (must start with a forward slash): › /
? Port: › (31299)
? Static path (must start with a forward slash): › /
  • Would you like to use TypeScript? (toggle): choose whether to generate a TypeScript or JavaScript configuration file.
  • Choose API type (select): select the type of API to generate mock examples for. Options: REST, GraphQL, or Both.
  • Base URL (string): set the base URL path for the mock server. Must start with /. Default: /.
  • Port (number): set the port number for the mock server. Default: 31299.
  • Static path (string): set the static assets path for the mock server. Must start with /. Default: /.

On this page