NestJS - InterceptorsYou want to hide the user's password field from all API responses using response transformation. Which approach is best in NestJS?ACreate an interceptor that maps the response and deletes the password fieldBModify the database schema to exclude passwordCUse a middleware to filter out password from requestsDSend password as null in the controller methodsCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand response transformation goalWe want to remove sensitive info from outgoing responses, not database or requests.Step 2: Choose best NestJS methodInterceptors can transform responses globally, ideal for removing password fields before sending.Step 3: Evaluate other optionsModifying DB schema or middleware won't affect response data; setting password null in controllers is repetitive.Final Answer:Create an interceptor that maps the response and deletes the password field -> Option AQuick Check:Use interceptor to hide sensitive response data [OK]Quick Trick: Use interceptor to remove sensitive fields from responses [OK]Common Mistakes:Trying to filter password in middleware (affects requests)Changing database schema instead of responseManually nulling password in every controller
Master "Interceptors" in NestJS9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More NestJS Quizzes Database with Prisma - Prisma migrations - Quiz 12easy Database with TypeORM - Repository pattern - Quiz 12easy Guards - Why guards control access - Quiz 13medium Guards - Guard binding levels - Quiz 12easy Interceptors - Logging interceptor - Quiz 11easy Interceptors - Why interceptors add cross-cutting logic - Quiz 8hard Middleware - Why middleware processes requests before handlers - Quiz 9hard Middleware - Why middleware processes requests before handlers - Quiz 4medium Pipes - Custom pipes - Quiz 12easy Pipes - Built-in pipes (ParseIntPipe, ParseBoolPipe) - Quiz 13medium