Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

nestjs ratelimit

// app.module.ts
import { Module } from '@nestjs/common';
import { APP_GUARD } from '@nestjs/core';
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';

@Module({
  imports: [
    ThrottlerModule.forRoot({
   	  ttl: 60, // Time to live, in seconds
      limit: 10, // Requests within the TTL
    }) 
  ],
  providers: [
    {
      provide: APP_GUARD,
      useClass: ThrottlerGuard,
    } // To guard globally
  ]
})
export class AppModule {}
 
PREVIOUS NEXT
Tagged: #nestjs #ratelimit
ADD COMMENT
Topic
Name
7+3 =