Reference

CLI

Complete reference for the mocko command. For a guided tour of the same options, see Running Mocko: CLI.

Usage

mocko [options] [path to mocks folder]
mocko validate [options] <path to mocks folder>

The mocks folder is optional; without it, file mocks are disabled for the session. Requires Node.js 20.19 or newer, installed with npm install -g @mocko/cli.

Options

FlagDefaultDescription
-h, --helpShow usage help.
-v, --versionShow the installed version.
-w, --watchoffWatch the mocks folder and reload on file changes.
-p, --port8080Port for the mock server.
-u, --urlunsetProxy target for requests no mock matches. Unset means unmatched requests return 404.
-t, --timeout30000Max milliseconds to wait for a proxied response.
--no-uiUI onDisable the control panel.
-r, --redisunsetRedis URL enabling Redis mode, e.g. redis://localhost:6379.
-P, --ui-port6625Port for the control panel.

mocko validate

mocko validate [options] <path to mocks folder>

Checks every mock in the folder and exits with code 1 if any of them is broken, without starting a server. Problems that are only warnings when the server starts fail validation, which makes it a good gate for CI. See Validate Mocks in CI for a complete pipeline.

Validation fails on:

  • HCL files that fail to parse (these are ignored at startup)
  • Invalid mock or host definitions: unknown methods, invalid status codes, conflicting format and Content-Type, and similar
  • Routes that fail to map, such as two mocks on the same method and path or query parameters in the path
  • Template bodies that fail to compile (these mocks respond 500 to every request)
  • Mocks on the reserved /__mocko__ path
  • Folders with no mocks at all

Suspicious but valid definitions produce warnings instead: paths with Express-style :param parameters, * wildcards, or ${param} placeholders, and mocks referencing a host that no host block defines. Warnings do not fail validation unless --strict is set.

FlagDefaultDescription
-h, --helpShow usage help.
-s, --strictoffTreat warnings as errors.
-j, --jsonoffPrint a machine-readable JSON report instead of the human output.

Exit code 0 means the folder is valid, anything else means it is not: validation errors, warnings under --strict, or a folder that does not exist.

Examples

$mocko --watch mocks
$mocko -p 4000 -u https://demo-api.mockoapp.net --watch mocks
$mocko --no-ui -r redis://localhost:6379 mocks

Notes

  • The UI is enabled by default; the CLI generates a fresh internal secret per run to connect it to the mock server.
  • Hidden files and folders (names starting with a dot) inside the mocks folder are ignored.
  • On unsupported Node versions the CLI exits with a link to the update instructions instead of failing later at runtime.