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

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?

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

Hey @security-geoscienti1 :wave:

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?

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.

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

Adding External Libraries in Postman | Postman Blog

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)

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)

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