Unable to use Request module in js library

Im attempting to use the request and limiter modules in a test and getting an error. My code and error looks like this;

var request = require('request');
var RateLimiter = require('limiter').RateLimiter;

var limiter = new RateLimiter(100, 1000);
var throttledRequest = function() {
    var requestArgs = routes;
    limiter.removeTokens(1, function() {
        request.apply(this, requestArgs);
    });
};

Error | Cannot find module ‘request’

Hey @Derrick.Boyd,

Welcome to the Postman community!! :wave:

I’m not sure where you’ve found an example saying that you could use those modules within the sandbox but it’s not actually possible.

There are only a limited number of external modules that can be used in the Sandbox environment, the full list can be found here:

The most obvious cause is that you did not install the request module locally in your node project.

npm install request --save

Not exactly sure how to do that? Where am placing that script?

Are you trying to do this within the Postman application? Or on an external node project?

In the postman application. I didnt think adding additional modules was possible inside of postman

There are a few hacky ways that folks have tried but you can’t add those modules like that.

That’s why I replied with this… :slight_smile:

You have use the code generator for NodeJs. So I have assumed that you are using node.

require(…) does not work in Postman.

What the problem you are trying to solve?

I have an array of requests I need to send.
ex;
var routes = [
https://route1.com
https://route2.com
https://route 3.com
]

The array can be quite large so I to limit the amount of requests that can be sent per second. I also want to implement exponential back off just in case the response is slower then expected but I haven’t gotten that far yet

You are kindof at the limits of what Postman can do. Consider looking into tools like JMeter or Gatling for setting such params.

You can add a delay after each request, thus limiting how many requests you send. I would export the list of requests to an external file and use them as iterations.

You cannot increase or decrease the rate.

Alternatively, you can simply build your own NodeJs script and run it separately from Postman.