Skip to content

Eitol/cli

 
 




@Mockoon/cli

Welcome to Mockoon's official CLI, a lightweight and fast NPM package to deploy your mock APIs anywhere. Feed it with a Mockoon's export file, and you are good to go.

The CLI supports the same features as the main application: templating system, proxy mode, route response rules, etc.

Mockoon CLI screenshot

Installation

$ npm install -g @mockoon/cli

Usage:

$ mockoon-cli COMMAND

Export your mock to use in the CLI

The CLI is compatible with Mockoon export files starting from version 1.7.0.

To export your environment(s) to use them in the CLI, follow these steps:

  1. Open the Import/export application menu and choose Mockoon's format -> Export all environments to a file (JSON) or Mockoon's format -> Export current environment to a file (JSON).

    Export to a file

    You can also right-click on one of the environments and select Copy to clipboard (JSON). You will then have to manually create a file and paste the environment's JSON data.

    Export to a file

  2. Choose a folder to save the JSON file.

  3. Use the start command below to launch your mock APIs with the CLI:

    $ mockoon-cli start --data ~/path/to/your-file.json -i 0
    

You will find more details in the official documentation.

Compatibility

Node.js

Mockoon's CLI has been tested on Node.js versions 10, 12, 14, and 15.

Mockoon data files

The CLI can import and migrate data from older versions of Mockoon. If you exported the data file with a more recent version of the application, you may need to update your CLI with the following command: npm install -g @mockoon/cli.

Commands

mockoon-cli start

Starts a mock API from a Mockoon's export file environment. As an export file can contain multiple environments, you can indicate the one you want to run by specifying its index in the file or its name. The process will be created by default with the name and port of the Mockoon's environment. You can override these values by using the --port and --pname flags.

USAGE
  $ mockoon-cli start

OPTIONS
  -d, --data=data    (required) Path or URL to your Mockoon data export file
  -i, --index=index  Environment's index in the data file
  -n, --name=name    Environment name in the data file
  -p, --port=port    Override environment's port
  -N, --pname=pname    Override process name
  -h, --help         show CLI help

EXAMPLES
  $ mockoon-cli start --data ~/export-data.json
  $ mockoon-cli start --data ~/export-data.json --index 0
  $ mockoon-cli start --data https://file-server/export-data.json --index 0
  $ mockoon-cli start --data ~/export-data.json --name "Mock environment"
  $ mockoon-cli start --data ~/export-data.json --name "Mock environment" --pname "proc1"

mockoon-cli list [ID]

Command alias: info

Lists all the running mock APIs and display some information: process name, pid, status, cpu, memory, port. You can also get the same information for a specific mock API by providing its pid or name.

USAGE
  $ mockoon-cli list

ARGUMENTS
  ID  Running API pid or name

OPTIONS
  -h, --help  show CLI help

EXAMPLE
  $ mockoon-cli list
  $ mockoon-cli info
  $ mockoon-cli list 0
  $ mockoon-cli list "Mock_environment"

mockoon-cli stop [ID]

Stops one or more running processes. When 'all' is provided, all processes will be stopped.

USAGE
  $ mockoon-cli stop [ID]

ARGUMENTS
  ID  Running API pid or name

OPTIONS
  -h, --help  show CLI help

EXAMPLE
  $ mockoon-cli stop
  $ mockoon-cli stop 0
  $ mockoon-cli stop "name"
  $ mockoon-cli stop "all"

mockoon-cli dockerize

Generates a Dockerfile used to build a self-contained image of a mock API. After building the image, no additional parameters will be needed when running the container. This command takes similar flags as the start command.

Please note that this command will extract your Mockoon environment from the export file you provide and put it side by side with the generated Dockerfile. Both files are required in order to build the image.

For more information on how to build the image: Using the dockerize command

USAGE
  $ mockoon-cli dockerize

OPTIONS
  -d, --data=data    (required) Path or URL to your Mockoon data export file
  -i, --index=index  Environment's index in the data file
  -n, --name=name    Environment name in the data file
  -p, --port=port    Override environment's port
  -o, --output       Generated Dockerfile path and name (e.g. `./Dockerfile`)
  -h, --help         show CLI help

EXAMPLES
  $ mockoon-cli dockerize --data ~/export-data.json --output ./Dockerfile
  $ mockoon-cli dockerize --data ~/export-data.json --index 0 --output ./Dockerfile
  $ mockoon-cli dockerize --data https://file-server/export-data.json --index 0 --output ./Dockerfile
  $ mockoon-cli dockerize --data ~/export-data.json --name "Mock environment" --output ./Dockerfile

mockoon-cli help [COMMAND]

Returns information about a command.

USAGE
  $ mockoon-cli help [COMMAND]

ARGUMENTS
  COMMAND  command to show help for

OPTIONS
  --all  see all commands in CLI

Docker

Using the generic Docker image

A generic Docker image is published on the Docker Hub Mockoon CLI repository. It uses node:14-alpine and installs the latest version of Mockoon CLI.

All of mockoon-cli start flags (--port, --index, etc.) must be provided when running the container.

To load the Mockoon data, you can either mount a local data file and pass mockoon-cli start flags at the end of the command:

docker run -d --mount type=bind,source=/home/your-data-file.json,target=/data,readonly -p 3000:3000 mockoon/cli:latest -d data -i 0 -p 3000

Or directly pass a URL to the mockoon-cli start command, without mounting a local data file:

docker run -d -p 3000:3000 mockoon/cli:latest -d https://raw.githubusercontent.com/mockoon/mock-samples/main/samples/generate-mock-data.json -i 0 -p 3000

Using the dockerize command

You can use the dockerize command to generate a new Dockerfile that will allow you to build a self-contained image. Thus, no Mockoon CLI specific parameters will be needed when running the container.

  • Run the dockerize command:

    mockoon-cli dockerize --data ./sample-data.json --port 3000 --index 0 --output ./tmp/Dockerfile

  • navigate to the tmp folder, where the Dockerfile has been generated:

    cd tmp

  • Build the image:

    docker build -t mockoon-mock1 .

  • Run the container:

    docker run -d -p <host_port>:3000 mockoon-mock1

Logs

Logs are located in ~/.mockoon-cli/logs/{mock-name}-[error|out].log.

The error.log file contains mostly server errors that occur at startup time and prevent the mock API to run (port already in use, etc.). They shouldn't occur that often.

The out.log file contains all other log entries (all levels) produced by the running mock server. Most of the errors occurring in Mockoon CLI (or the main application) are not critical and therefore considered as normal output. As an example, if the JSON body from an entering request is erroneous, Mockoon will log a JSON parsing error, but it won't block the normal execution of the application.

PM2

Mockoon CLI uses PM2 to start, stop or list the running mock APIs. Therefore, you can directly use PM2 commands to manage the processes.

Mockoon's documentation

You will find Mockoon's documentation on the official website. It covers the most complex features.

Sponsors

If you like Mockoon, you can support the project with a one-time donation: Paypal Buy Me A Coffee

You can also sponsor the maintainer (255kb) on GitHub and join all the Sponsors and Backers who helped this project over time!

Support/feedback

You can discuss all things related to Mockoon's CLI, and ask for help, on the official community. It's also a good place to discuss bugs and feature requests before opening an issue on this repository. For more chat-like discussions, you can also join our Discord server.

Contributing

If you are interested in contributing to Mockoon, please take a look at the contributing guidelines.

Please also take a look at our Code of Conduct.

Roadmap

If you want to know what will be coming in the next release you can check the global Roadmap.

New releases will be announced on Mockoon's Twitter account @GetMockoon and through the newsletter to which you can subscribe here.

About

Mockoon's official CLI. Deploy your mock APIs anywhere.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • TypeScript 91.9%
  • JavaScript 7.1%
  • Other 1.0%