Unable to use external js library

I’m trying to use external js module (speakeasy). I have tried setting it as global var, $.getscript, cheerio .
But I get error complaining about a module which is used within the js library.
‘Cannot find module base32.js’

Can please somebody help? What am I doing wrong
This is kind of deciding factor for us to use postman , if we cannot use external libraries.

Add me to the list as well. I was about to post a similar thread. There appears to be a wholesale issue with Postman using some portions of the js libraries, even those that are supposedly core to Node.js such as the process module. I get the exact same error.as you when attempting to require another package that I’ve installed via npm. I’ve tried pathing to it using the info I can find about pathing to js packages and still it gives the error.

Thanks for making this thread, hopefully we can get some attention on this issue.

@abhijitkane @shamasis - I don’t know whom to really ask this. But I need help with it, if anybody can look into it or at least direct me to right person.

Thanks for pinging me directly. Can you tell me which function is error if out? If you can paste a snippet of an erring script, I will trace the function and see what’s going on.

Postman script running sandbox goes a long way to ensure that scripts cannot masquerade over your system. A side-effect of that is some libraries misbehave when we put them in such environment - since their developers assume its a full-blown NodeJS environment. Nonetheless, most of these errors are fixable.

Hey, can you try and isolate the issue so that we are sure that it is because of the non-compliance of the said module?

Try to add your script as an environment variable by isolating the modules that are causing issues using postman.setGlobalVariable(). Once that is done, try to load it with eval(postman.getGlobalVariable("environment variable key"));

If you’re able to then access the methods of your added script in the new file without any issues, try adding the non-compliant modules and see if the issue persists. If it does, we’d be able to pinpoint the issue better. Alternatively, you can also try loading the erroring modules in the same fashion by setting it as an environment variable and see if you are able to do it or not.

Keep us posted.

The library I’m trying to use :
postman.setGlobalVariable(‘speakeasy’, responseBody);

In the test :
mfaCode = speakeasy.totp({
encoding : ‘base32’

Error : Cannot find module base32.js

Hey @dotdash,

I tried out using speakeasy with Postman. There are two parts to this.

  1. The source file for speakeasy you are trying to use with Postman is a node variant. That is why Postman could not recognize the base32.js module, because that is not available in the script sandbox. To make sure all the dependencies are available, you have to use a bundled version. I was able to get

working with a browserified version of speakeasy

  1. The second part of the problem is the sandboxed script environment does not have all the modules that are available in a typical browser or node environemnt. That is why I could not get encoding : ‘base32’ working. base32.js requires crypto which is not available yet.

We are working on reducing this kind of complexities and adding most of the native modules available.

@kamalaknn - Thanks for the reply , but I’m not sure what you mean by bundled version?
Also , you got it working with postman you mean?


This is what I did to create a browserified bundle of speakeasy in Postman,

# clone speakeasy, and npm install
browserify -e index.js -o speakeasy.js -s speakeasy

(If you’re trying this out as an alternative you might want to couple a minify step to reduce bundle size)

I then hosted the output file in a localhost server and added a request to it in the collection. Then added the following to test script

mfaCode = speakeasy.totp({
    secret : ‘7OB55B4HM7ILXKIA4LWQ3WKO1TI5CBNP’