Node.js / NestJS

Validation & DTO

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

20 câu hỏi phỏng vấn·
Junior
1

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

Câu trả lời

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?

Câu trả lời

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?

Câu trả lời

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 câu hỏi phỏng vấn

Nắm vững Node.js / NestJS cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí