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

@nestjs/throttler

Package Overview
Dependencies
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestjs/throttler

A Rate-Limiting module for NestJS to work on Express, Fastify, Websockets, Socket.IO, and GraphQL, all rolled up into a simple package.

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
252K
decreased by-25.62%
Maintainers
3
Weekly downloads
 
Created

What is @nestjs/throttler?

@nestjs/throttler is a rate-limiting module for NestJS applications. It helps to control the rate of incoming requests to prevent abuse and ensure fair usage of resources. This package is particularly useful for APIs to avoid being overwhelmed by too many requests in a short period.

What are @nestjs/throttler's main functionalities?

Basic Rate Limiting

This feature allows you to set up basic rate limiting for your entire application. In this example, a maximum of 10 requests per minute is allowed.

```typescript
import { ThrottlerModule } from '@nestjs/throttler';

@Module({
  imports: [
    ThrottlerModule.forRoot({
      ttl: 60,
      limit: 10,
    }),
  ],
})
export class AppModule {}
```

Rate Limiting for Specific Routes

This feature allows you to apply rate limiting to specific routes. In this example, the 'limited' route is restricted to 5 requests per minute.

```typescript
import { Controller, Get, UseGuards } from '@nestjs/common';
import { ThrottlerGuard, Throttle } from '@nestjs/throttler';

@Controller('api')
@UseGuards(ThrottlerGuard)
export class ApiController {
  @Get('limited')
  @Throttle(5, 60)
  getLimited() {
    return 'This route is rate limited to 5 requests per minute';
  }
}
```

Customizing Rate Limiting

This feature allows you to customize the rate limiting storage mechanism. In this example, Redis is used as the storage backend for rate limiting.

```typescript
import { ThrottlerModule, ThrottlerGuard, ThrottlerStorageRedisService } from '@nestjs/throttler';
import { Module } from '@nestjs/common';
import { APP_GUARD } from '@nestjs/core';

@Module({
  imports: [
    ThrottlerModule.forRoot({
      ttl: 60,
      limit: 10,
      storage: new ThrottlerStorageRedisService(),
    }),
  ],
  providers: [
    {
      provide: APP_GUARD,
      useClass: ThrottlerGuard,
    },
  ],
})
export class AppModule {}
```

Other packages similar to @nestjs/throttler

Keywords

FAQs

Package last updated on 26 Feb 2021

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