# Load Node-forge library in Postman pre request scrip

**URL:** <https://community.postman.com/t/load-node-forge-library-in-postman-pre-request-scrip/38279>\
**Category:** Help Hub\
**Tags:** library, pre-request-script, rsa\
**Created:** [August 18, 2022, 2:52am UTC](https://community.postman.com/t/load-node-forge-library-in-postman-pre-request-scrip/38279 "2022-08-18T02:52:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sreekar23071999](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/sreekar23071999/32/12950_2.png) [@Sreekar23071999](https://community.postman.com/u/Sreekar23071999)\
**Post date:** [August 18, 2022, 2:52am UTC](https://community.postman.com/t/load-node-forge-library-in-postman-pre-request-scrip/38279/1 "2022-08-18T02:52:07Z")

</div>

I’m trying to load node-forge which has an implementation of PKSC#1 into postman as a pre-request script

```auto
pm.sendRequest("https://unpkg.com/node-forge@1.0.0/dist/forge.min.js", function(err, res) {
    (new Function(res.text()))();
    console.log(forge)
})

```

but getting below error

```auto
ReferenceError: window is not defined

```

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [August 18, 2022, 3:02am UTC](https://community.postman.com/t/load-node-forge-library-in-postman-pre-request-scrip/38279/2 "2022-08-18T03:02:54Z")

</div>

Hi @Sreekar23071999

Have a look at this…

> **[Adding External Libraries in Postman | Postman Blog](https://blog.postman.com/adding-external-libraries-in-postman/)**
>
> Learn how to use the libraries included in the Postman sandbox, then review some methods for adding your own external libraries.

---

<div class="post-metadata">

**Author:** ![Sreekar23071999](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/sreekar23071999/32/12950_2.png) [@Sreekar23071999](https://community.postman.com/u/Sreekar23071999)\
**Post date:** [August 18, 2022, 5:16am UTC](https://community.postman.com/t/load-node-forge-library-in-postman-pre-request-scrip/38279/3 "2022-08-18T05:16:05Z")

</div>

Hello @w4dd325

Getting the same error “ReferenceError: window is not defined” even after adding it as mentioned in the above article.

```auto
pm.sendRequest("https://unpkg.com/node-forge@1.0.0/dist/forge.min.js", function(err, res) {
   pm.collectionVariables.set("forge_library", res.text());
   eval(pm.collectionVariables.get("forge_library"));
   console.log(this.forge)
})

```

 ![Screenshot 2022-08-18 at 10.43.05 AM](https://us1.discourse-cdn.com/getpostman/original/2X/b/b90817f3d7921f3ef207ccc929795818a3912513.png)

---

<div class="post-metadata">

**Author:** ![Sreekar23071999](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/sreekar23071999/32/12950_2.png) [@Sreekar23071999](https://community.postman.com/u/Sreekar23071999)\
**Post date:** [August 18, 2022, 5:18am UTC](https://community.postman.com/t/load-node-forge-library-in-postman-pre-request-scrip/38279/4 "2022-08-18T05:18:17Z")

</div>

**Postman Version** 9.28.2  
UI Version: 9.28.2-ui-220812-1517  
Desktop Platform Version: 9.27.0 (9.27.0)

**OS:** macOS Monterey

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [August 18, 2022, 9:29am UTC](https://community.postman.com/t/load-node-forge-library-in-postman-pre-request-scrip/38279/5 "2022-08-18T09:29:10Z")

</div>

It looks like the lib interacts with a browser window… But Postman is built more like a basic nodeJS, it doesn’t have a browser window to interact with.

> [_Postman_ has a powerful runtime](https://learning.postman.com/docs/writing-scripts/intro-to-scripts/) based on _Node_ ._js_ that allows you to add dynamic behavior to requests and collections.

I think this is the issue, Postman doesn’t know how to interpret the browser parts of the lib.

---

<div class="post-metadata">

**Author:** ![Sreekar23071999](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/sreekar23071999/32/12950_2.png) [@Sreekar23071999](https://community.postman.com/u/Sreekar23071999)\
**Post date:** [August 18, 2022, 10:30am UTC](https://community.postman.com/t/load-node-forge-library-in-postman-pre-request-scrip/38279/6 "2022-08-18T10:30:41Z")

</div>

Thanks for the reply @w4dd325

I’m trying to do PKCS#1\_1.5 encryption on my request payload before firing the API but the inbuilt CryptoJS doesn’t support any RSA Schemes, so I was trying to import a lib that has this implementation so far all my attempts have been futile, happen to know any JS libs that implement PKCS#1\_1.5 and work in postman?  
Native crypto module of node.js does support this, is there a way to access the same on postman?

---

<div class="post-metadata">

**Author:** ![Stitches](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/stitches/32/13133_2.png) [@Stitches](https://community.postman.com/u/Stitches)\
**Post date:** [September 4, 2022, 8:23am UTC](https://community.postman.com/t/load-node-forge-library-in-postman-pre-request-scrip/38279/7 "2022-09-04T08:23:52Z")

</div>

Managed to get this to work by creating an empty window object

window = {};  
eval(pm.globals.get(‘forge’) );

---

<div class="post-metadata">

**Author:** ![febriyan1302](https://avatars.discourse-cdn.com/v4/letter/f/d9b06d/32.png) [@febriyan1302](https://community.postman.com/u/febriyan1302)\
**Post date:** [September 14, 2022, 7:46pm UTC](https://community.postman.com/t/load-node-forge-library-in-postman-pre-request-scrip/38279/8 "2022-09-14T19:46:04Z")

</div>

and then i’ve got error : **ReferenceError: URLSearchParams is not defined**

 ![Screen Shot 2022-09-15 at 02.45.08](https://us1.discourse-cdn.com/getpostman/original/2X/5/5936278e33018070e3270a844704c19d3677472a.png)

---

<div class="post-metadata">

**Author:** ![febriyan1302](https://avatars.discourse-cdn.com/v4/letter/f/d9b06d/32.png) [@febriyan1302](https://community.postman.com/u/febriyan1302)\
**Post date:** [September 14, 2022, 9:12pm UTC](https://community.postman.com/t/load-node-forge-library-in-postman-pre-request-scrip/38279/9 "2022-09-14T21:12:51Z")

</div>

Hi All, Finally it’s working on me.  
Follow this tutorial : [Node Forge For Postman](https://github.com/loveiset/RSAForPostman)
