Node.js / NestJS

Validation & DTO

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

20 perguntas de entrevistaยท
Junior
1

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

Resposta

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?

Resposta

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?

Resposta

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 perguntas de entrevista

Domine Node.js / NestJS para sua proxima entrevista

Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.

Comece gratis