Performance: Whitelist and transform options
This affects the request processing speed and memory usage by controlling which properties are accepted and how input data is transformed before reaching business logic.
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));app.useGlobalPipes(new ValidationPipe({ whitelist: false, transform: false }));| Pattern | CPU Usage | Memory Usage | Validation Speed | Verdict |
|---|---|---|---|---|
| Whitelist: false, Transform: false | High (manual checks) | Higher (extra data kept) | Slower (manual parsing) | [X] Bad |
| Whitelist: true, Transform: true | Lower (automatic filtering) | Lower (only needed data) | Faster (auto conversion) | [OK] Good |
whitelist option do when enabled in NestJS validation pipe?whitelist and transform options in a global validation pipe in NestJS?whitelist: true and transform: true?
class UserDto {
name: string;
age: number;
}
const input = { name: 'Alice', age: '30', extra: 'remove me' };whitelist: true but forgot transform: true in your ValidationPipe. What issue might you face when receiving input with number fields as strings?forbidNonWhitelisted: true throw errors on extras instead of removing; others disable whitelist or transform or lack transformOptions.Pass the test and this pattern moves unknown