# How to use external npm package

**URL:** <https://community.postman.com/t/how-to-use-external-npm-package/19443>\
**Category:** Help Hub\
**Tags:** modules, npm\
**Created:** [January 22, 2021, 3:20pm UTC](https://community.postman.com/t/how-to-use-external-npm-package/19443 "2021-01-22T15:20:52Z")\
**Posts on this page:** 5\
**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:** [January 22, 2021, 3:20pm UTC](https://community.postman.com/t/how-to-use-external-npm-package/19443/1 "2021-01-22T15:20:52Z")

</div>

I want to use this [npm package](https://www.npmjs.com/package/image-to-base64)

```auto
    window = {};
    pm.sendRequest("https://unpkg.com/image-to-base64@2.1.1/image-to-base64.min.js", (error, response) => {
    var text = response.text();
    (new Function(text))();

    window.imageToBase64("https://images.unsplash.com/photo-1611270629569-948d94ca915a?ixid=MXwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwyfHx8ZW58MHx8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60")
        .then(
            (response) => {
                console.log(response);
            }
        )
        .catch(
            (error) => {
                console.log(error);
            }
        )
    });

```

But this didn’t work and shows me this error **ReferenceError: module is not defined**  
I also tried this code

```auto
    const imagebase64 = pm.environment.get("imagebase64");

    (new Function(imagebase64))();

    imagebase64("https://images.unsplash.com/photo-1611326758959-07fb4a250fcc?ixid=MXwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwyfHx8ZW58MHx8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60")

```

this is also showing me this error **SyntaxError: Unexpected token ‘}’**

Please anyone help me with this

---

<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:** [January 23, 2021, 5:43pm UTC](https://community.postman.com/t/how-to-use-external-npm-package/19443/2 "2021-01-23T17:43:57Z")

</div>

You need to use eval to run the code you have fetched from [unpkg.com](http://unpkg.com).

Here is a tutorial I did a while back demonstrating this concept.

[![](https://img.youtube.com/vi/dO7JTDS2V50/maxresdefault.jpg "How to handle responses CSV format in Postman?") ](https://www.youtube.com/watch?v=dO7JTDS2V50)

I hope this helps. If you get stuck, let me know.

---

<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:** [January 23, 2021, 5:50pm UTC](https://community.postman.com/t/how-to-use-external-npm-package/19443/3 "2021-01-23T17:50:28Z")

</div>

thanks  
I’ll check it out

---

<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, 10:07am UTC](https://community.postman.com/t/how-to-use-external-npm-package/19443/4 "2025-04-14T10:07:29Z")

</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, 10:07am UTC](https://community.postman.com/t/how-to-use-external-npm-package/19443/5 "2025-04-14T10:07:39Z")

</div>

Closed on April 14, 2025, 10:07am UTC


