Use external javascript library within "Pre-request script"?

Does the ā€˜requireā€™ facility available in the ā€œPre-request scriptā€ area allow for the use of any external JS library?

If so, where do the libraries have to installed? (Iā€™m on Windows 10)

Iā€™m looking to use ā€˜jwt-simpleā€™ (https://github.com/hokaccha/node-jwt-simple#readme)

@davout_uk I am afraid you wonā€™t be able to do that.
You can give this a read: https://learning.getpostman.com/docs/postman/scripts/postman_sandbox/

There are a few popular inbuilt libraries that you can use which are documented in the above mentioned link.

One way I have seen as a workaround is that you hit the CDN / url of the library using Postman and then you can use JSON.stringify and store the JS library code in an environment variable.

Then you can just do a JSON.parse / eval on the environment variable in any request and use all the functions of the library.
This is just a workaround.

1 Like