Node.js / NestJS

NestJS Modules & DI

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

20 gespreksvragen·
Mid-Level
1

What is a module in NestJS?

Antwoord

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?

Antwoord

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?

Antwoord

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 gespreksvragen

Beheers Node.js / NestJS voor je volgende gesprek

Krijg toegang tot alle vragen, flashcards, technische tests, code review-oefeningen en gespreksimulatoren.

Begin gratis