# In Newman used as package how to retrieve an environment variable during the iteration?

**URL:** <https://community.postman.com/t/in-newman-used-as-package-how-to-retrieve-an-environment-variable-during-the-iteration/13838>\
**Category:** Help Hub\
**Created:** [July 2, 2020, 12:38pm UTC](https://community.postman.com/t/in-newman-used-as-package-how-to-retrieve-an-environment-variable-during-the-iteration/13838 "2020-07-02T12:38:24Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![udit](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/udit/32/5056_2.png) [@udit](https://community.postman.com/u/udit)\
**Post date:** [July 27, 2020, 5:46am UTC](https://community.postman.com/t/in-newman-used-as-package-how-to-retrieve-an-environment-variable-during-the-iteration/13838/13 "2020-07-27T05:46:51Z")

</div>

@aurelien.lair Variables are accessible in `script`, `prerequest`, and, `test` events as well.  
Refer the below snippet:

```auto
newman.run({
    collection: {
        item: {
            request: 'http://postman-echo.com/get',
            event: [{
                listen: 'test',
                script: 'pm.environment.set("resp", pm.response.json());'
            }]
        }
    },
    reporters: ['cli']
}).on('script', function (err, args) {
    !err && console.info(args.execution.environment.values.toJSON());
}).on('test'/* or, prerequest */, function (err, args) {
    !err && console.info(args.executions[0].result.environment.values.toJSON());
});

```

---

_[View the full topic](https://community.postman.com/t/in-newman-used-as-package-how-to-retrieve-an-environment-variable-during-the-iteration/13838)._
