Node.js / NestJS

NestJS Modules & DI

Modular architecture, imports/exports, forRoot/forFeature, dynamic modules, circular dependencies

20 câu hỏi phỏng vấn·
Mid-Level
1

What is a module in NestJS?

Câu trả lời

A module is a class annotated with the @Module() decorator that organizes code in a cohesive way. It encapsulates a set of providers, controllers, and other modules, allowing the application to be structured into modular components. Each NestJS application has at least one root module that serves as the entry point.

2

What is the role of the 'providers' property in the @Module() decorator?

Câu trả lời

The providers property declares services and other classes that can be injected by the Dependency Injection system. These providers are instantiated by the NestJS container and can be shared within the module. They represent the business logic of the application and are accessible via dependency injection.

3

How to make a provider available to other modules?

Câu trả lời

To make a provider accessible from other modules, it must be added to the exports array of the @Module() decorator. Only exported providers can be injected into other modules that import this module. This allows precise control over a module's public API and encapsulation of internal implementation.

4

What is the difference between 'imports' and 'exports' in a module?

5

What is Dependency Injection (DI) in NestJS?

+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í