Mock server commands

View as Markdown

This topic covers mock server commands for the Postman CLI.

postman mock run

You can use the postman mock run command to start a code mock from a configuration file. The command isn’t supported for code mocks in the Postman cloud.

To run a collection against a code mock, use the --mock option with the postman collection run command.

This command starts a code mock from a configuration file in JSON format. With the configuration file, you can configure details like the mock’s port number, name, script, and more. The mock runs on the specified port until you stop it. Make sure you also have a JavaScript file with an HTTP server that sets the request and example response for simulating real API behavior.

Add the command to your CI/CD script to start a code mock as a dependency for your application or test suite. Once running, your service or external tests can send requests to it as if it were a real API. This enables you to simulate API behavior for testing and development.

Learn more at Simulate APIs with code mock servers.

Usage

$postman mock run <config-file>
<config-file>

The path to the mock server configuration file in JSON format.

Options

-e, --environment <path>

Specifies the path to an environment file (JSON or YAML) loaded into pm.environment for the mock server’s scripts.

-g, --globals <path>

Specifies the path to a globals file (JSON or YAML) loaded into pm.globals for the mock server’s scripts.

Example

$postman mock run mock-config.json
$
$postman mock run mock-config.json --environment ./postman/environments/dev.yaml