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


#1

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)


#2

@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 on the environment variable in any request and use all the functions of the library.
This is just a workaround.