Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

limiter

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

limiter

A generic rate limiter for node.js. Useful for API clients, web crawling, or other tasks that need to be throttled

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.6M
decreased by-55.27%
Maintainers
1
Weekly downloads
 
Created

What is limiter?

The 'limiter' npm package is used to control the rate of operations in Node.js applications. It allows you to limit the number of operations that can be performed over a given period of time, which is useful for rate-limiting API requests, managing resource usage, and preventing abuse.

What are limiter's main functionalities?

Basic Rate Limiting

This feature allows you to limit the number of operations to a specified number per interval. In this example, the limiter allows 5 requests per second. If the limit is exceeded, it logs 'Rate limit exceeded'.

const { RateLimiter } = require('limiter');

const limiter = new RateLimiter({ tokensPerInterval: 5, interval: 'second' });

async function makeRequest() {
  const remainingRequests = await limiter.removeTokens(1);
  if (remainingRequests >= 0) {
    console.log('Request allowed');
  } else {
    console.log('Rate limit exceeded');
  }
}

makeRequest();

Custom Intervals

This feature allows you to set custom intervals for rate limiting. In this example, the limiter allows 10 requests per minute.

const { RateLimiter } = require('limiter');

const limiter = new RateLimiter({ tokensPerInterval: 10, interval: 60000 }); // 10 requests per minute

async function makeRequest() {
  const remainingRequests = await limiter.removeTokens(1);
  if (remainingRequests >= 0) {
    console.log('Request allowed');
  } else {
    console.log('Rate limit exceeded');
  }
}

makeRequest();

Rate Limiting with Bursts

This feature allows for bursts of requests to be made immediately up to the limit, and then enforces the rate limit. In this example, the limiter allows 5 requests per second and can handle bursts.

const { RateLimiter } = require('limiter');

const limiter = new RateLimiter({ tokensPerInterval: 5, interval: 'second', fireImmediately: true });

async function makeRequest() {
  const remainingRequests = await limiter.removeTokens(1);
  if (remainingRequests >= 0) {
    console.log('Request allowed');
  } else {
    console.log('Rate limit exceeded');
  }
}

makeRequest();

Other packages similar to limiter

Keywords

FAQs

Package last updated on 17 Apr 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc