Unable to launch Newman javascript API run command

Archived topic — this may be out of date.
Newman has been replaced by the Postman CLI, Postman’s official, signed command-line tool. It runs collections as Newman did, and also lints API specs, runs mocks and monitors, and syncs local files with Postman from your terminal, CI/CD pipeline or coding agent.
Working with an AI coding agent? The Postman plugin lets agents in Claude Code, Cursor, Codex and others design, mock, test and ship APIs with Postman.
For current help, see the Postman docs, try the free Postman tools (no account needed), or join us on Discord.

My question:
I have a collection that I’m trying to automate as part of launching my company’s API service. Currently the collection works in Postman, but I’m trying to add the automation portion of running it with Newman.

I have a javascript module build that runs the process from what I’ve read in the documentation:

const main = async () => {
  const regionName = process.env['REGION_NAME'];
  const environment = process.env['ENVIRONMENT'];
  const mfaToken = process.env['MFA_TOKEN'];
  const accessToken = process.env['ACCESS_TOKEN'];
  const userEmail = process.env['USER_EMAIL'];
  const userPassword = process.env['USER_PASSWORD'];

  const config = await buildConfig(regionName, environment);

  const newmanConfig = {
    collection,
    environment: {
      id: "bd5fbe4a-a5af-4536-9e94-7c66a14ec6a5",
      name: config.apiEnvironment,
      values: [
        {
          key: 'itglue',
          value: config.baseUrl,
          enabled: true
        },
        {
          key: "itglue-api",
          value: config.apiUrl,
          enabled: true
        },
        {
          key: 'refresh_subdomain',
          value: config.subdomain,
          enabled: true
        },
        {
          key: 'jwt_subdomain',
          value: config.subdomain,
          enabled: true
        },
        {
          key: 'api-token',
          value: accessToken,
          enabled: true
        },
        {
          key: 'mfa_token',
          value: mfaToken,
          enabled: true
        },
        {
          key: 'user_email',
          value: userEmail,
          enabled: true
        },
        {
          key: 'user_password',
          value: userPassword,
          enabled: true
        }
      ],
      _postman_variable_scope: "environment",
      _postman_exported_at: "2022-08-18T14:38:14.591Z",
      _postman_exported_using: "Postman/9.28.2"
    },
    reporters: ['cli', 'junit'],
    reporter: {
      junit: {
        export: join(
          process.cwd(),
          './resources/reports/it-glue-newman-report.xml'
        )
      }
    }
  }

  newman.run(newmanConfig)
    .on('start', (err, args) => {
      if (err) throw err;
      console.log('======== Run Api Tests... ========')
    })
    .on('done', (err, summary) => {
      if (err) {
        throw err;
      } else if (summary.error) {
        throw summary.error;
      } else {
        console.log(summary.run);
      }
    });
};

However, in testing, I can’t get the start event to emit. The application completes without executing any of the Newman tests for the API.

I’m kind of stumped as to what is going wrong at this point. Anyone have any thoughts?

How I found the problem:
Trying to run Newman with my configuration.

I’ve already tried:

  • Writing the script as solely CommonJS instead of a ESM Module
  • Changing Newman’s import to use CommonJS instead of ESM import
  • Using a callback function instead of the EventEmitter events
  • Using Newman from the commandline (this works)

Thanks for your post, and sorry we didn’t get to this sooner. This isn’t the experience we want for our users.

Since the post is a bit older, we’re closing it to make room for newer discussions. If you’re still experiencing this or have new details to share, we’d love for you to start a new discussion.