Mock Config logoMock config

Init

Create a mock-config-server template from the command line

Creates a mock configuration. It generates a mock-server.config.(js|ts) file in the current directory. An interactive flow lets you choose between TypeScript and JavaScript, select an API preset, 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.7777
--staticPath-sSpecify the static assets path. Must start with /.

Interactive flow

The command asks a few short questions:

? Would you like to use TypeScript? › Yes / No
? Choose API type (Use arrow keys)
 REST
  REST playground
  GraphQL
  GraphQL playground
  WebSocket
  Full API
? Base URL (must start with a forward slash): › /
? Port: › (7777)
? 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 API preset for the generated config. Options: REST, REST playground, GraphQL, GraphQL playground, WebSocket, or Full API.
  • 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: 7777.
  • Static path (string): set the static assets path for the mock server. Must start with /. Default: /.

Presets

PresetDescription
RESTBasic REST users example with list and item routes.
REST playgroundREST users example with CRUD routes.
GraphQLBasic GraphQL users example with list and item queries.
GraphQL playgroundGraphQL users example with CRUD operations.
WebSocketWebSocket connection and message example.
Full APIREST, GraphQL, and WebSocket examples in one config.

On this page