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
| Flag | Default | Description |
|---|---|---|
-h, --help | Show usage help. | |
-v, --version | Show the installed version. | |
-w, --watch | off | Watch the mocks folder and reload on file changes. |
-p, --port | 8080 | Port for the mock server. |
-u, --url | unset | Proxy target for requests no mock matches. Unset means unmatched requests return 404. |
-t, --timeout | 30000 | Max milliseconds to wait for a proxied response. |
--no-ui | UI on | Disable the control panel. |
-r, --redis | unset | Redis URL enabling Redis mode, e.g. redis://localhost:6379. |
-P, --ui-port | 6625 | Port 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
formatand 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.
| Flag | Default | Description |
|---|---|---|
-h, --help | Show usage help. | |
-s, --strict | off | Treat warnings as errors. |
-j, --json | off | Print 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
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.