Node.js / NestJS

Validation & DTO

class-validator, class-transformer, DTOs, ValidationPipe, custom validators, sanitization

20 preguntas de entrevista·
Junior
1

What is a DTO (Data Transfer Object) in NestJS?

Respuesta

A DTO is a TypeScript class that defines the structure of data transferred between client and server. It acts as a data contract and enables automatic input validation using decorators like @IsString or @IsNumber. DTOs improve security by filtering unauthorized properties and make code maintenance easier.

2

Which package allows adding validation constraints to DTOs?

Respuesta

The class-validator package provides validation decorators like @IsString, @IsEmail, @Min, @Max that allow defining validation rules on DTO properties. It works in tandem with ValidationPipe to automatically validate incoming data. This package is widely used in the NestJS ecosystem to ensure data integrity.

3

Which decorator validates that a property is a string?

Respuesta

The @IsString decorator verifies that a property is of type string. It applies directly to the DTO property and automatically rejects any value that is not a string. This decorator is one of the most commonly used as it covers a very common validation case in REST APIs.

4

Where should ValidationPipe be configured to validate all application routes?

5

Which decorator validates that a field is not empty?

+17 preguntas de entrevista

Domina Node.js / NestJS para tu próxima entrevista

Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.

Empieza gratis