# How to integrate external npm package

**URL:** <https://community.postman.com/t/how-to-integrate-external-npm-package/22192>\
**Category:** Help Hub\
**Created:** [April 2, 2021, 6:25am UTC](https://community.postman.com/t/how-to-integrate-external-npm-package/22192 "2021-04-02T06:25:54Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![thefierycoder](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@thefierycoder](https://community.postman.com/u/thefierycoder)\
**Post date:** [April 2, 2021, 6:25am UTC](https://community.postman.com/t/how-to-integrate-external-npm-package/22192/1 "2021-04-02T06:25:54Z")

</div>

Hello Everyone,  
I want to know how to integrate [this npm package](https://www.npmjs.com/package/postman-to-openapi) in my test script.

I tried a couple of solutions but nothing works for me.  
Please help me with this.

Thanks

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [April 6, 2021, 6:30pm UTC](https://community.postman.com/t/how-to-integrate-external-npm-package/22192/2 "2021-04-06T18:30:19Z")

</div>

What have you tried?

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [April 7, 2021, 2:31am UTC](https://community.postman.com/t/how-to-integrate-external-npm-package/22192/3 "2021-04-07T02:31:22Z")

</div>

Hey @thefierycoder 👋

As I understand it, you want to convert collection file to OpenAPI spec file using this library, correct?

In general, you can download an external library using `pm.sendRequest` and evaluate it with `eval()` as shown in an example [here](https://community.postman.com/t/epoch-time-with-18-digits/19672).

But you cannot directly access local filesystem from scripts in Postman due to security reasons as mentioned [here](https://community.postman.com/t/is-it-possible-to-send-an-image-file-in-the-pre-request-script-of-a-request/4577/5), so it would be quite challenging to use that library from test scripts in Postman (the only workaround would be to set up a local server that access to your local file system and call the server from Postman).

Hopefully this clarifies a bit. Please do feel free to let me know if anything in my response needs further clarification 🙂

---

<div class="post-metadata">

**Author:** ![thefierycoder](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@thefierycoder](https://community.postman.com/u/thefierycoder)\
**Post date:** [April 7, 2021, 3:03am UTC](https://community.postman.com/t/how-to-integrate-external-npm-package/22192/4 "2021-04-07T03:03:13Z")

</div>

@taehoshino Thanks for your help.

I’ll check the linked resources then let you know.

In the package repo, there is not any min.js file, so, which js file should I call and eval() from the postman?

**UPDATE** :  
I checked all the linked resources.  
I have some doubts:

1. Which js file should I call from the postman because we don’t have a min.js file of that package?

2. How to access that input collection file and read that file in the postman app?  
I saw [this article](https://blog.postman.com/write-to-your-local-file-system-using-a-postman-collection/) that tells how to write on a disk using a local server but How should I get the file path so, we can pass that path to the npm package?

This npm package also has some dependencies in order to work.

---

<div class="post-metadata">

**Author:** ![thefierycoder](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@thefierycoder](https://community.postman.com/u/thefierycoder)\
**Post date:** [April 7, 2021, 3:28am UTC](https://community.postman.com/t/how-to-integrate-external-npm-package/22192/5 "2021-04-07T03:28:08Z")

</div>

Hello @vdespa ,

I tried what you told on one of your youtube videos.

But you used the .min.js file to send the request to the package and then you save it to the env but in my case, there is not any .min.js file.

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [April 8, 2021, 3:05am UTC](https://community.postman.com/t/how-to-integrate-external-npm-package/22192/6 "2021-04-08T03:05:33Z")

</div>

Hey @thefierycoder 👋

This [`index.js`](https://github.com/joolfe/postman-to-openapi/blob/master/lib/index.js) seems to be the main js file, but looking at it, we can see this file itself is requiring some external libraries like `fs`. Even if we can import this library, we would then need to import additional libraries that are being required (it’s gonna be very messy if not impossible 🙁 ).

If what you want to achieve here is to trigger the conversion of collection file to OpenAPI schema file from Postman, you can set up a local server using nodeJS and simply requiring the `postman-to-openapi` library from your nodeJS code like in [the blog post](https://blog.postman.com/write-to-your-local-file-system-using-a-postman-collection/).  
Then you can send a request to that local server - maybe you can pass the file path to the collection file in the request, which can be passed to `postmanToOpenApi`.

 ![Screen Shot 2021-04-08 at 1.03.42 pm](https://us1.discourse-cdn.com/getpostman/original/3X/d/a/da7097f7ffd7c95da3083b5e0d955abf95a05d83.png)

Hope this helps! Let me know if you have any question 🙂

---

<div class="post-metadata">

**Author:** ![thefierycoder](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@thefierycoder](https://community.postman.com/u/thefierycoder)\
**Post date:** [April 8, 2021, 3:33am UTC](https://community.postman.com/t/how-to-integrate-external-npm-package/22192/7 "2021-04-08T03:33:02Z")

</div>

@taehoshino Thanks for your help!

That’s what I am planning to do!🙂

Will setup a local server and make a post request to.  
It’ll be easy for me

I want a suggestion:

If I make a wrapper npm package for this package that takes a collection id instead of a file and then in the script file we’ll make requests to the Postman api to get the particular collection json and then save it to temp folder then pass that file to that package.

Will this wrapper package helpful for the community?

One issue I found in this approach is the postman api key?

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [April 13, 2021, 1:33am UTC](https://community.postman.com/t/how-to-integrate-external-npm-package/22192/8 "2021-04-13T01:33:37Z")

</div>

Hey @thefierycoder 👋

I am sure such an implementation would be helpful 🙂  
If you can share in your own GitHub repo, other users will be able to utilize it with ease.

---

<div class="post-metadata">

**Author:** ![thefierycoder](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@thefierycoder](https://community.postman.com/u/thefierycoder)\
**Post date:** [April 13, 2021, 2:11am UTC](https://community.postman.com/t/how-to-integrate-external-npm-package/22192/9 "2021-04-13T02:11:40Z")

</div>

For now, I made this npm package to convert a postman collection to openapi via CLI.

> **[postman-to-openapi-cli](https://www.npmjs.com/package/postman-to-openapi-cli)**
>
> Convert Postman Collection v2.0/v2.1 to OpenAPI v3.0 via CLI

---

<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:** [April 14, 2025, 9:27am UTC](https://community.postman.com/t/how-to-integrate-external-npm-package/22192/10 "2025-04-14T09:27:58Z")

</div>

Hey everyone 👋,

We have released support for external packages in the latest version of Postman, you can read more about this here:

> <https://github.com/postmanlabs/postman-app-support/issues/13542>
>
> We’re excited to announce a powerful new capability in Postman’s scripting envir…onment — support for \*\*external public packages from the \[NPM\](https://www.npmjs.com/) and \[JSR\](https://jsr.io/) registries\*\*! 🎉
> 
> With this release, you can now seamlessly supercharge your pre-request and post-response scripts using your favorite open-source packages right from inside Postman.
> 
> 
> \## 📽️ Feature Walkthrough
> 
> Getting up and running is easy:
> 1. Open the \*\*Scripts\*\* tab (Pre-request or Post-response) for any HTTP Request.
> 2. Click on the \*\*Packages\*\* dropdown to search and select a package from \*\*NPM\*\* or \*\*JSR\*\*.
> 3. Or, directly import packages into your script using \[pm.require\](https://learning.postman.com/docs/tests-and-scripts/write-scripts/postman-sandbox-api-reference/#import-packages-from-scripts). Examples:
> \`\`\`js
> // From NPM
> const lodash = pm.require("npm:lodash@4.17.21");
> 
> // From JSR
> const shortUUID = pm.require("jsr:@opensrc/short-uuid")
> \`\`\`
> 
> https://github.com/user-attachments/assets/c39c4951-f92d-4477-8b68-f2a573c80141
> 
> \> 📚 Read the \[full documentation here\](https://learning.postman.com/docs/tests-and-scripts/write-scripts/packages/external-package-registries/) for more examples, caveats, and advanced usage.
> 
> \## 🛠️ Planned Work Ahead
> 
> We’re just getting started! Here's what we're working on next:
> \- \*\*Adding auto-suggestions\*\* in the scripts tab for packages you import — making it even easier to discover and use package APIs as you type.
> \- \*\*Extending package support across all protocols\*\*, including gRPC, GraphQL, etc.
> \- \*\*Bringing this feature to Postman CLI and Monitors\*\* so your workflows stay consistent across all Postman tools.
> 
> Stay tuned! 💥
> 
> \## ⚠️ Known Limitations
> 
> While this is a huge leap forward, here are a few limitations to be aware of:
> \- Postman's script environment is platform-agnostic. This means Packages that rely on \[Node.js built-ins\](https://nodejs.org/api/modules.html#built-in-modules) like \`child\_process\` or \`worker\_threads\` may not work as expected. We offer best-effort implementations of Node built-ins, but they may not have complete parity with Node.js.
> \- Packages that reference globals outside the \[allowed sandbox environment\](https://learning.postman.com/docs/tests-and-scripts/write-scripts/postman-sandbox-api-reference/#use-global-objects) may not behave correctly, depending on the part of the package that is executed.
> \- Packages that use Top-level \`await\` are not supported at the moment.
> 
> \## 🙌 Thank You!
> 
> This was long overdue and wouldn’t have been possible without the incredible feedback and support from our Postman community. Your insights and use cases helped shape this—please keep it coming!
> 
> Happy Scripting!

---

<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:** [April 14, 2025, 3:45pm UTC](https://community.postman.com/t/how-to-integrate-external-npm-package/22192/11 "2025-04-14T15:45:25Z")

</div>

Closed on April 14, 2025, 3:45pm UTC


