# How to run a node app.js then set env variable of postman

**URL:** <https://community.postman.com/t/how-to-run-a-node-app-js-then-set-env-variable-of-postman/51085>\
**Category:** Help Hub\
**Tags:** development\
**Created:** [August 29, 2023, 12:36am UTC](https://community.postman.com/t/how-to-run-a-node-app-js-then-set-env-variable-of-postman/51085 "2023-08-29T00:36:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![security-geoscienti1](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/security-geoscienti1/32/16583_2.png) [@security-geoscienti1](https://community.postman.com/u/security-geoscienti1)\
**Post date:** [August 29, 2023, 12:36am UTC](https://community.postman.com/t/how-to-run-a-node-app-js-then-set-env-variable-of-postman/51085/1 "2023-08-29T00:36:10Z")

</div>

I want to run a app.js and this app.js will return a json object, then I want to set env varible according to this app.js’ returned value in post man. How?

---

<div class="post-metadata">

**Author:** ![security-geoscienti1](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/security-geoscienti1/32/16583_2.png) [@security-geoscienti1](https://community.postman.com/u/security-geoscienti1)\
**Post date:** [August 29, 2023, 12:44am UTC](https://community.postman.com/t/how-to-run-a-node-app-js-then-set-env-variable-of-postman/51085/2 "2023-08-29T00:44:25Z")

</div>

I didn’t use that pre-script because it will fail when running my package

---

<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:** [August 30, 2023, 1:17pm UTC](https://community.postman.com/t/how-to-run-a-node-app-js-then-set-env-variable-of-postman/51085/3 "2023-08-30T13:17:42Z")

</div>

Hey @security-geoscienti1 👋

Given the limited amount of information that you’ve provided, it’s difficult to understand what you’re looking to achieve here.

Could you expand on the question and the overall use case, please?

---

<div class="post-metadata">

**Author:** ![security-geoscienti1](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/security-geoscienti1/32/16583_2.png) [@security-geoscienti1](https://community.postman.com/u/security-geoscienti1)\
**Post date:** [August 30, 2023, 10:26pm UTC](https://community.postman.com/t/how-to-run-a-node-app-js-then-set-env-variable-of-postman/51085/4 "2023-08-30T22:26:33Z")

</div>

Hi @danny-dainton ,

Sorry for unclear, we current have a js script that using couple of libraries to retrieve some credentials, and we tried to use that tricky way to use libary in pre-request script but failed, so I’m thinking if there are some way that allow us to run `node app.js` then env variable automatically updated according to the json object this `app.js` returns.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [August 31, 2023, 9:06am UTC](https://community.postman.com/t/how-to-run-a-node-app-js-then-set-env-variable-of-postman/51085/5 "2023-08-31T09:06:17Z")

</div>

The Postman sandbox only has access to a limited set of external libraries.

[Adding External Libraries in Postman | Postman Blog](https://blog.postman.com/adding-external-libraries-in-postman/)

The blog link above also talks about pulling a library from a CDN, but the library needs to be completely self contained, it can’t rely on downstream libraries like most of the useful ones do. (Also means it can’t be a node JS library as you won’t have access to the modules).

My suggestion would be for your dev’s to extend the JavaScript app you have into a proper API, so it can be called as part of a work flow or by using sendRequest in a pre-request script.

The final option is to use Newman which is built on node.js.

[newman - npm (npmjs.com)](https://www.npmjs.com/package/newman)

It’s main use case is to run it in a command line as part of your build pipeline, but it can also include it as a library in a node JS application.

[newman - npm (npmjs.com)](https://www.npmjs.com/package/newman#using-newman-as-a-library)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [September 3, 2023, 11:09pm UTC](https://community.postman.com/t/how-to-run-a-node-app-js-then-set-env-variable-of-postman/51085/6 "2023-09-03T23:09:23Z")

</div>

Closed on September 3, 2023, 11:09pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
