New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nestlab/rate-limit

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestlab/rate-limit

Module for limiting the number of requests in a given time period.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

Rate limit module

Module for limiting the number of requests in a given time period.

Install

$ npm i @nestlab/rate-limit

Configuration

Example

RateLimitModule.forRoot({
    // Optional. Default message for rate limit exception
    rateLimitMessage: 'You made a lot of requests. Try again later',

    // Optional. Default token provider function for identify requests
    defaultTokenProvider: req => req.ip,

    // Optional. Enable for environments 
    enableForEnvironments: ['production', 'staging']
});

Usage

@Controller()
export class AppController {
	@RateLimit(2000) // one request in 2 seconds for each IP address
	@Get('endpoint1')
	endpoint1(): string {
		return 'ENDPOINT 1 RESPONSE';
	}

	@RateLimit(10000, 5) // 5 requests in 10 seconds for each IP address
	@Get('endpoint2')
	endpoint2(): string {
		return 'ENDPOINT 2 RESPONSE';
	}

	@RateLimit(10000, 5, req => req.user.userId) // 5 requests in 10 seconds for each user
	@Get('endpoint3')
	endpoint3(): string {
		return 'ENDPOINT 3 RESPONSE';
	}
}

Enjoy!

Keywords

FAQs

Package last updated on 01 Jul 2020

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