# Newman with variable

**URL:** <https://community.postman.com/t/newman-with-variable/18970>\
**Category:** Help Hub\
**Tags:** newman-project, variables\
**Created:** [January 8, 2021, 2:48pm UTC](https://community.postman.com/t/newman-with-variable/18970 "2021-01-08T14:48:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pr85](https://avatars.discourse-cdn.com/v4/letter/p/a183cd/32.png) [@pr85](https://community.postman.com/u/pr85)\
**Post date:** [January 8, 2021, 2:48pm UTC](https://community.postman.com/t/newman-with-variable/18970/1 "2021-01-08T14:48:53Z")

</div>

> **Archived topic — this may be out of date.**  
> Newman has been replaced by the **[Postman CLI](https://learning.postman.com/docs/postman-cli/postman-cli-overview/)**, 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](https://github.com/postmanlabs/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](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

I’ve been using newman to do some automation, but I’m now beginning to hit a wall when I use it with node.js. Here’s the node.js code

```auto
const newman = require('newman');

newman.run({
     collection: require('./my.json'),
     iterationData: require('./my.csv'),
     iterations: 5,
     reporters: 'cli'
}).on('beforeRequest', function (error, args) {
     if (error) {
         console.error(error);
     } else {
         // Log the request body
         console.log(args.request.body.raw);
     }
}).on('request', function (error, args) {
     if (error) {
         console.error(error);
     }
     else {
         // Log the response body
         console.log(args.response.stream.toString());
     }
});

```

When I run this code, it cannot process the URL which includes a variable with double curly braces, i.e. [http://myserver/{{variable}}](http://myserver/%7B%7Bvariable%7D%7D)

When I run node.js with a the above javascript. I get

> ReferenceError: variable is not defined

it’s not a parameter, so it’s not a key-value pair.

Thoughts?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 8, 2021, 6:44pm UTC](https://community.postman.com/t/newman-with-variable/18970/2 "2021-01-08T18:44:10Z")

</div>

Not really sure what’s happening without more details but `iterations` should be `iterationCount`. As you’re using a data file, that’s not really needed as that should control that value.

Are you able to share the full error message you see? What is `variable` and is that contained in your collection somewhere?

---

<div class="post-metadata">

**Author:** ![pr85](https://avatars.discourse-cdn.com/v4/letter/p/a183cd/32.png) [@pr85](https://community.postman.com/u/pr85)\
**Post date:** [January 8, 2021, 7:00pm UTC](https://community.postman.com/t/newman-with-variable/18970/3 "2021-01-08T19:00:25Z")

</div>

The variable is the last part of the URL in the curly braces above. It’s not a key value pair. As far as the full error:

> /Users/pr85/Downloads/my.csv:1  
> variable  
> ^
> 
> ReferenceError: variable is not defined  
> at Object. (/Users/pr85/Downloads/my.csv:1:2)  
> at Module.\_compile (node:internal/modules/cjs/loader:1102:14)  
> at Object.Module.\_extensions…js (node:internal/modules/cjs/loader:1131:10)  
> at Module.load (node:internal/modules/cjs/loader:967:32)  
> at Function.Module.\_load (node:internal/modules/cjs/loader:807:14)  
> at Module.require (node:internal/modules/cjs/loader:991:19)  
> at require (node:internal/modules/cjs/helpers:92:18)  
> at Object. (/Users/pr85/Downloads/test.js:5:20)  
> at Module.\_compile (node:internal/modules/cjs/loader:1102:14)  
> at Object.Module.\_extensions…js (node:internal/modules/cjs/loader:1131:10)  
> at Module.load (node:internal/modules/cjs/loader:967:32)  
> at Function.Module.\_load (node:internal/modules/cjs/loader:807:14)  
> at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run\_main:76:12)  
> at node:internal/main/run\_main\_module:17:47

When I run newman with -d option, same file, it works as expected and substitutes the variable correctly.

P.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 8, 2021, 8:51pm UTC](https://community.postman.com/t/newman-with-variable/18970/4 "2021-01-08T20:51:10Z")

</div>

In that context, that’s not really interacting with the Collection because it’s not getting to that point yet.

If it was, you would be seeing the CLI output from the Newman run but it’s not even running it.

It’s more than likely the `.csv` file itself, what does that look like? Can you show an example?

Have you also tried this without wrapping that with those `require()` methods?

---

<div class="post-metadata">

**Author:** ![pr85](https://avatars.discourse-cdn.com/v4/letter/p/a183cd/32.png) [@pr85](https://community.postman.com/u/pr85)\
**Post date:** [January 11, 2021, 1:39pm UTC](https://community.postman.com/t/newman-with-variable/18970/5 "2021-01-11T13:39:27Z")

</div>

@danny-dainton thanks the csv file is simply, it’s this:

variable,value1,value2,valuei3,value4

I’ll try removing the require.

P.
