Sometimes, we want to throttle the number of API requests per second in Node.js.
In this article, we’ll look at how to throttle the number of API requests per second in Node.js.
How to throttle the number of API requests per second in Node.js?
To throttle the number of API requests per second in Node.js, we can use the simple-rate-limiter package.
We install it by running
npm i simple-rate-limiter
Then we use it by writing
const limit = require("simple-rate-limiter");
const request = limit(require("request")).to(10).per(1000);
We call limit with the request module.
And we limit the number of requests to 10 per second with .to(10).per(1000).
Conclusion
To throttle the number of API requests per second in Node.js, we can use the simple-rate-limiter package.