What is a key advantage of NestJS’s modular architecture for building a Node.js application compared to a traditional Express setup?

4 phương ánCó giải thích

Các phương án trả lời

Chọn một phương án
Lời giảiChọn phương án để mở
Đáp án đúng: "NestJS organizes code into reusable modules with controllers and services". Kiến trúc của NestJS xoay quanh module: mỗi lớp gắn @Module() gom controllers (nhận request), providers như service (chứa logic nghiệp vụ) cùng khai báo imports, exports, nhờ đó từng tính năng như users hay auth được đóng gói riêng, tái sử dụng và kiểm thử được nhờ dependency injection; Express thuần chỉ có router và middleware, cấu trúc thư mục do mỗi nhóm tự đặt. "NestJS eliminates the need for middleware" sai vì NestJS vẫn có middleware, mặc định chạy trên chính Express, và còn thêm guard, interceptor, pipe. "NestJS automatically handles database migrations for MongoDB" sai vì Nest không tự chạy migration; việc đó do ORM hay công cụ riêng đảm nhận. "NestJS provides built-in support for real-time WebSocket communication" có phần đúng vì Nest có gói @nestjs/websockets với gateway, nhưng đó là một tính năng phụ trợ, không phải lợi thế của kiến trúc module mà câu hỏi nhắm tới.

Cùng chương 11

Xuất hiện trong 1 bộ đề