
NestJS Modules & DI
Modular architecture, imports/exports, forRoot/forFeature, dynamic modules, circular dependencies
1What is a module in NestJS?
What is a module in NestJS?
Answer
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.
2What is the role of the 'providers' property in the @Module() decorator?
What is the role of the 'providers' property in the @Module() decorator?
Answer
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.
3How to make a provider available to other modules?
How to make a provider available to other modules?
Answer
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.
What is the difference between 'imports' and 'exports' in a module?
What is Dependency Injection (DI) in NestJS?
+17 interview questions
Other Node.js / NestJS interview topics
Node.js Fundamentals
Node.js Core APIs
Asynchronous Programming
Express.js Basics
NestJS Fundamentals
REST API Design
Validation & DTO
API Documentation & Contracts
Error Handling
Unit Testing
Task Scheduling
Configuration & Environment Management
JWT Authentication
Authorization & RBAC
Database with TypeORM
Prisma ORM
Middleware & Interceptors
File Upload
WebSockets
GraphQL with NestJS
End-to-End Testing
Caching with Redis
Queues with Bull
DevOps, Logging & CI/CD
Docker & Containerization
Microservices
Security Best Practices
Performance & Cloud Deployment
Master Node.js / NestJS for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free