# Pass Environment Variables out of Newman into NodeJs environment for further use

**URL:** <https://community.postman.com/t/pass-environment-variables-out-of-newman-into-nodejs-environment-for-further-use/3610>\
**Category:** Help Hub\
**Created:** [December 14, 2018, 8:56pm UTC](https://community.postman.com/t/pass-environment-variables-out-of-newman-into-nodejs-environment-for-further-use/3610 "2018-12-14T20:56:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![C\_Tag\_Trapeze](https://avatars.discourse-cdn.com/v4/letter/c/90db22/32.png) [@C\_Tag\_Trapeze](https://community.postman.com/u/C_Tag_Trapeze)\
**Post date:** [December 14, 2018, 8:56pm UTC](https://community.postman.com/t/pass-environment-variables-out-of-newman-into-nodejs-environment-for-further-use/3610/1 "2018-12-14T20:56:58Z")

</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).

In my scenario I need to use Node as the operating environment and pass variables out of Newman and used from within the .js that will be executing the script to start the collection:

```
newman.run({
    collection: require('./somename.postman_collection.json'),
    reporters: ['cli', 'html']
	delay: ['200']
	}).on('beforeRequest', function (error, args) {
    if (error) {
        console.error(error);
    } else {
        fs.writeFile(`request.txt`, args.request.body.raw, function (error) {
            if (error) { 
                console.error(error); 
            }
        });    
    }
}).on('request', function (error, args) {
    if (error) {
        console.error(error);
    }
    else {
        fs.writeFile(`response${getDateString()}.txt`, args.response.stream, function (error) {
            if (error) { 
                console.error(error); 
            }
        });        
    }
});

```

This .js will also be processing some data-files (which are the names of the variables that would be passed out of Newman) then use the new data-file (using appendFile to make multiple files one larger file) as input for the collection to be run. The alternative would be to use JS to make the HTTP:POST request and parse the JSON outside of Newman; however, this solution has eluded me as well. Any help would be GREATLY appreciated.

---

<div class="post-metadata">

**Author:** ![bilelhmam07](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@bilelhmam07](https://community.postman.com/u/bilelhmam07)\
**Post date:** [August 7, 2019, 6:16pm UTC](https://community.postman.com/t/pass-environment-variables-out-of-newman-into-nodejs-environment-for-further-use/3610/2 "2019-08-07T18:16:49Z")

</div>

hi,

Had you found a solution?  
I have the same problem. I want to get variable from Newman using js.

---

<div class="post-metadata">

**Author:** ![C\_Tag\_Trapeze](https://avatars.discourse-cdn.com/v4/letter/c/90db22/32.png) [@C\_Tag\_Trapeze](https://community.postman.com/u/C_Tag_Trapeze)\
**Post date:** [August 7, 2019, 6:44pm UTC](https://community.postman.com/t/pass-environment-variables-out-of-newman-into-nodejs-environment-for-further-use/3610/3 "2019-08-07T18:44:01Z")

</div>

I was unable to solve this problem; however, I just worked around it by only using Newman to perform small functions, not as I originally intended but in the end the solution was resolved/fixed. I have spoken to others familiar with node and Newman, and to their knowledge, passing variables out of newman and into another js is not possible.

I was originally using Newman to run everything in the collection; however, I settled for using Newman for a small portion of the original requests in the collection and the requests that I needed to have variables for - I wrote some small JS scripts using Axios to make the requests, parse the info I needed and create variables from them, then utilized basic callbacks and/or Promises when needed. Hope this helps.

---

<div class="post-metadata">

**Author:** ![krunallathiya21.kl](https://avatars.discourse-cdn.com/v4/letter/k/e0b2c6/32.png) [@krunallathiya21.kl](https://community.postman.com/u/krunallathiya21.kl)\
**Post date:** [May 3, 2020, 1:42pm UTC](https://community.postman.com/t/pass-environment-variables-out-of-newman-into-nodejs-environment-for-further-use/3610/4 "2020-05-03T13:42:28Z")

</div>

In [Axios](https://appdividend.com/2018/08/30/getting-started-with-axios-tutorial-example/), responses are already served as a javascript object, no need to parse, simply get a response and access data.

I was originally using Newman to run everything in the collection; however, I settled for using Newman for a small portion of the original requests in the collection and the requests.
