title: Postman - Newman running from NodeJS
body: <p>In order to save the response from postman API calls, I am executing Postman collection using newman run.</p>
  <p>The collection runs when running using</p>
  <pre><code>newman run C:\TasteBud\NewMan\JSON-Order_collection.json --env-var unique_order_id=OD-06-07-I2Q5-JYRY5ARPN --environment C:\TasteBud\NewMan\EnvironmentJSON.json
  </code></pre>
  <p>However when I run the same collection as part of javascript or nodejs script.</p>
  <pre><code>node writeToFile.js    
  </code></pre>
  <p>it throws error as node <em>&quot;1⠄ JSONError in test-script  &quot;</em>  refer attached image. I need to pass the auth token generated by login request to subsequent request. So I have variable assignment in the &quot;test&quot;.</p>
  <pre><code>let response = pm.response.json();
  pm.environment.set(&quot;auth_token&quot;, response.data.auth_token);
  console.log(pm.response.json().data.auth_token);
  </code></pre>
  <p>Why cant I have &quot;test&quot; ? if no then how can I pass/set these environment variable for subsequent API call ?</p>
  <p>Code inside writeToFile.js is here. <a href="https://pastebin.com/W35RgfJX" rel="nofollow noreferrer">writeToFile.js</a></p>
  <p><a href="https://i.stack.imgur.com/PejLR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PejLR.png" alt="Successful run using command line" /></a></p>
  <p><a href="https://i.stack.imgur.com/LnBGa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LnBGa.png" alt="Calling via NodeJS" /></a></p>
  <p><a href="https://i.stack.imgur.com/58VD2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/58VD2.png" alt="Javascript in test to get auth-token" /></a></p>