Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the ThrottlerModule in a NestJS module.
NestJS
import { Module } from '@nestjs/common'; import { ThrottlerModule } from '@nestjs/throttler'; @Module({ imports: [ThrottlerModule.[1]({ ttl: 60, limit: 10 })], }) export class AppModule {}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using forRootAsync without async configuration.
Using register which is not a method of ThrottlerModule.
Using create which does not exist.
✗ Incorrect
The ThrottlerModule is imported using the forRoot() method to set global rate limiting options.
2fill in blank
mediumComplete the code to apply the ThrottlerGuard globally in the module using providers.
NestJS
import { Module } from '@nestjs/common'; import { ThrottlerGuard } from '@nestjs/throttler'; import { [1] } from '@nestjs/core'; @Module({ providers: [ { provide: [1], useClass: ThrottlerGuard } ], }) export class AppModule {}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing CanActivate which is an interface, not a token.
Importing Guard which does not exist.
Importing Injectable which is a decorator.
✗ Incorrect
APP_GUARD is imported from '@nestjs/core' to provide global guard tokens. It is used as the provide token to register ThrottlerGuard as a global guard.
3fill in blank
hardFix the error in the controller method to apply rate limiting with @Throttle decorator.
NestJS
import { Controller, Get } from '@nestjs/common'; import { Throttle } from '@nestjs/throttler'; @Controller('cats') export class CatsController { @Get() @Throttle([1]) findAll() { return 'This action returns all cats'; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing an object instead of two numbers.
Using named parameters inside the decorator.
Passing a single number.
✗ Incorrect
The @Throttle decorator takes two positional arguments: limit and ttl (time to live in seconds). So @Throttle(10, 60) means max 10 requests per 60 seconds.
4fill in blank
hardFill both blanks to configure ThrottlerModule with a 30-second window and 5 requests limit.
NestJS
import { Module } from '@nestjs/common'; import { ThrottlerModule } from '@nestjs/throttler'; @Module({ imports: [ThrottlerModule.forRoot({ ttl: [1], limit: [2] })], }) export class AppModule {}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping ttl and limit values.
Using default values instead of specified ones.
✗ Incorrect
The ttl is the time window in seconds (30), and limit is the max requests allowed (5).
5fill in blank
hardFill all three blanks to create a custom ThrottlerGuard that ignores requests from admin users.
NestJS
import { Injectable, ExecutionContext } from '@nestjs/common'; import { ThrottlerGuard } from '@nestjs/throttler'; @Injectable() export class [1] extends ThrottlerGuard { protected getTracker(req: any): string { const user = req.user; if (user && user.role === [2]) { return [3]; } return super.getTracker(req); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class names.
Using role without quotes.
Returning wrong string to skip rate limiting.
✗ Incorrect
The class is named CustomThrottlerGuard, the role to check is 'admin', and returning 'skip' tells the guard to ignore rate limiting for that user.