7. Postman CLI: Newman

While the Postman desktop application is spectacular for designing and manually debugging APIs, it cannot be run easily on server terminals or head-less environments. To run your Postman collection tests straight inside a command line shell, Postman provides **Newman**—a command-line collection runner built on Node.js.

Why Use Newman?

Newman allows you to integrate Postman test suites into build systems. It is extremely lightweight, consumes minimal system memory, and can output multiple reporting formats (JSON, JUnit XML, or beautiful interactive HTML dashboards).

Installing Newman

Because Newman is written in Node.js, you must have Node.js (v12+) installed on your server. To install Newman globally, execute the following command in your terminal:

npm install -g newman

Verify the installation by checking the version:

newman --version

Step-by-Step: Running collections in CLI

Step 1: Export Assets from Postman

  1. In the Postman app, click the three dots next to your collection name and select **Export**. Select the latest recommended format (**Collection v2.1**) and save the resulting JSON file (e.g. `my_collection.json`).
  2. If using environment variables, click the Environment Settings gear icon, click the three dots next to your active environment (e.g., "Staging"), click **Export**, and save that JSON file too (e.g. `staging_env.json`).

Step 2: Run in Terminal

To execute your collection, run `newman run` followed by the path to the exported collection:

newman run my_collection.json

Step 3: Run with Environment Variables

If your collection references variable endpoints (like `{{baseUrl}}`), pass the environment JSON file using the -e flag:

newman run my_collection.json -e staging_env.json

Interactive HTML Reports

Terminal outputs are clean, but stakeholders prefer visual, human-scannable dashboards. You can generate a stunning interactive HTML report using the **newman-reporter-htmlextra** library:

1. Install the Reporter

npm install -g newman-reporter-htmlextra

2. Execute Newman with HTML Output

newman run my_collection.json -e staging_env.json -r htmlextra

Once completed, Newman will generate a file inside a `./newman/` folder. Opening this file in a browser displays a fully-stylized, premium web dashboard detailing every request, request headers, payload sizes, assertion results, and response codes!

Newman Pro Tip: You don't have to export JSON files constantly! If you are logged into your Postman account, you can generate a **Postman API Key** and run collections live from Postman cloud servers:
newman run "https://api.getpostman.com/collections/your-collection-id?apikey=your-api-key"