Registry / testing / newman

newman

JSON →
library0.6.7jsnpmunverified

Newman is a powerful command-line collection runner for Postman, enabling users to execute and test Postman collections directly from the command line without the Postman GUI. It is primarily designed for integration into continuous integration and continuous delivery (CI/CD) pipelines and other automated build systems to facilitate automated API testing. The current stable version is 6.2.2. While there isn't a fixed release cadence, the project is actively maintained, with major versions typically introducing Node.js compatibility updates and dependency upgrades (e.g., v6 was released in late 2023). Key differentiators include its seamless integration with Postman collections, support for various output reporters (CLI, JSON, JUnit, HTML), and its capability for programmatic use as a Node.js library, offering a robust solution for automated API testing workflows.

npm install newman
INSTALL
IMPORT
SIG · NEWMAN
N
newman
testingjavascriptv0.6.7
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

newman
import newman from 'newman';
import { newman } from 'newman'; const newman = require('newman').default;
Newman is typically imported as a default export for programmatic use. While CommonJS `require` is `const newman = require('newman');`, ESM usage usually involves a default import for CJS interoperability.
NewmanRunOptions
import type { NewmanRunOptions } from 'newman';
import { NewmanRunOptions } from 'newman'; import type NewmanRunOptions from 'newman';
Type imports should use `import type` for clarity and to avoid bundling issues in TypeScript projects. The types are part of the main package.
NewmanRunSummary
import type { NewmanRunSummary } from 'newman';
Import `NewmanRunSummary` as a type to access the structure of the run result object, useful for programmatic analysis and reporting.

This quickstart demonstrates how to programmatically run a Postman collection using Newman as a Node.js library, including specifying reporters and handling the run summary for success or failure states. It generates a temporary collection file and cleans it up after execution.

import newman from 'newman'; import path from 'path'; import fs from 'fs'; // Create a dummy collection file for demonstration const dummyCollectionPath = path.resolve(__dirname, 'dummy-collection.json'); const dummyCollectionContent = { "info": { "_postman_id": "b8c5f2b8-f3d9-4b6a-8b1b-c7e1e4f9b8c2", "name": "Dummy API Tests", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "item": [ { "name": "Test Get Request", "request": { "method": "GET", "header": [], "url": { "raw": "https://postman-echo.com/get?foo=bar", "protocol": "https", "host": ["postman-echo", "com"], "path": ["get"], "query": [ { "key": "foo", "value": "bar" } ] } }, "response": [] } ] }; fs.writeFileSync(dummyCollectionPath, JSON.stringify(dummyCollectionContent, null, 2)); console.log(`Running collection: ${dummyCollectionPath}`); newman.run({ collection: dummyCollectionPath, reporters: ['cli', 'json'], reporter: { json: { export: './newman-report.json' } }, environment: { // Example of passing environment variables programmatically values: [ { key: 'baseUrl', value: 'https://postman-echo.com', enabled: true } ] } }, (err, summary) => { // Clean up dummy file after run fs.unlinkSync(dummyCollectionPath); if (err) { console.error('Collection run encountered an error:', err); return; } if (summary.run.failures.length) { console.error('Collection run completed with failures:'); summary.run.failures.forEach(failure => { console.error(` - ${failure.error.message} in ${failure.source.name}`); }); } else { console.log('Collection run completed successfully!'); console.log(`Total requests: ${summary.run.stats.requests.total}`); console.log(`Total assertions: ${summary.run.stats.assertions.total}`); console.log(`Assertions failed: ${summary.run.stats.assertions.failed}`); console.log('JSON report generated at ./newman-report.json'); } });
newman --version
Debug
Known issues
breakingNewman v6.0 and newer versions require Node.js v16 or higher. Older Node.js versions (e.g., v10, v12, v14) are no longer supported. Attempting to run Newman v6 on an unsupported Node.js version will result in runtime errors.
fix
Upgrade your Node.js installation to version 16 or newer. Use `nvm` or your system's package manager for Node.js management.
affects: >=6.0.0
breakingNewman v6 includes significant dependency upgrades, particularly for the Postman Runtime and `tough-cookie`. These updates were made to address security vulnerabilities and introduce new features like JWT and NTLMv2 authentication.
fix
Ensure your project's dependencies are compatible. Review the official Newman migration guide for any behavioral changes in the Postman Runtime or script execution logic, especially if you relied on older `tough-cookie` behavior.
affects: >=6.0.0
gotchaNewman does not natively support OAuth 2.0 authentication directly within collections. While Postman can handle OAuth flows, when running with Newman, you'll need to manually manage and provide access tokens (e.g., via environment variables or pre-request scripts) to your requests.
fix
Obtain OAuth 2.0 tokens externally (e.g., through a separate script or Postman's GUI) and pass them to Newman as environment variables (`--env-var 'token=your_token'`) or through a Postman environment file.
affects: >=3.0.0
gotchaWhen running Newman in CI/CD environments, ensure that collection, environment, and data files are accessible via absolute or correct relative paths. Path inconsistencies are a common source of 'file not found' errors, especially when the working directory differs from local development.
fix
Use absolute paths for collection, environment, and data files within CI scripts, or explicitly set the working directory for the Newman command. For example, `newman run $(pwd)/path/to/collection.json`.
affects: >=3.0.0
gotchaSSL certificate verification can cause issues with self-signed certificates or specific corporate proxies. Newman offers an `--insecure` option to bypass SSL certificate validation, but use it with caution in production environments.
fix
For development/testing, use `newman run --insecure ...`. For production, configure proper CA certificates using `--ssl-extra-ca-certs` or ensure your environment trusts the certificates.
affects: >=3.0.0
Errors
Common errors & fixes
'newman' is not recognized as an internal or external command, operable program or batch file.
Newman is either not installed globally, or its npm global bin directory is not in your system's PATH environment variable.
fix
Install Newman globally: `npm install -g newman`. If already installed, ensure `$(npm config get prefix)/bin` (or `C:\Users\<YourUser>\AppData\Roaming\npm` on Windows) is in your system's PATH.
Cannot find module 'newman' Require stack:
You are trying to use Newman as a library in a Node.js project, but it's not installed as a local dependency or linked correctly.
fix
Install Newman as a local project dependency: `npm install newman`. If using TypeScript, also install types: `npm install @types/newman --save-dev`.
Error: unable to open collection file "<filename.json>".
The specified collection file path is incorrect, the file does not exist at that location, or there are file permission issues.
fix
Verify the file path and name are correct. Ensure the user running Newman has read permissions for the file. Use absolute paths, especially in CI/CD environments.
Error: Node.js v<X> is not supported. Please upgrade to Node.js v16 or higher.
You are running Newman v6 or newer on an unsupported Node.js version.
fix
Upgrade your Node.js environment to version 16 or later. For example, use `nvm install 16` and `nvm use 16`, or update your system's Node.js installation.
Upgrade
Version history
0.6.7latest on npm
Audit
Dependencies
noderequiredRequired runtime environment for execution. Newman is a Node.js module.
Agent activity
4 hits · last 30 days
node
4
Resources