Postman Tutorial
- 1. Introduction to Postman
- 2. Sending Requests & Body Types
- 3. Environments & Variable Scopes
- 4. Collections & Folders
- 5. Writing API Tests & Assertions
- 6. Automated Collection Runner
- 7. Postman CLI: Newman
- 8. Integration with CI/CD Pipelines
- 9. Mock Servers
- 10. API Monitoring & Uptime Alerting
- 11. Collaborative Workspaces
- 12. Generating API Documentation
- 13. Designing APIs (OpenAPI / Swagger)
- 14. Advanced Authorization
- 15. Postman Flows & Best Practices
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 newmanVerify the installation by checking the version:
newman --versionStep-by-Step: Running collections in CLI
Step 1: Export Assets from Postman
- 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`).
- 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.jsonStep 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.jsonInteractive 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-htmlextra2. Execute Newman with HTML Output
newman run my_collection.json -e staging_env.json -r htmlextraOnce 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 run "https://api.getpostman.com/collections/your-collection-id?apikey=your-api-key"