Performance: Root module (AppModule)
This affects the initial load time and startup performance of the NestJS application by controlling module imports and dependency injection setup.
import { Module } from '@nestjs/common'; import { UsersModule } from './users/users.module'; @Module({ imports: [UsersModule], }) export class AppModule {}
import { Module } from '@nestjs/common'; import { UsersModule } from './users/users.module'; import { OrdersModule } from './orders/orders.module'; import { PaymentsModule } from './payments/payments.module'; @Module({ imports: [UsersModule, OrdersModule, PaymentsModule], }) export class AppModule {}
| Pattern | Module Imports | Startup Delay | Memory Usage | Verdict |
|---|---|---|---|---|
| Import many feature modules in AppModule | High (3+ modules) | Blocks startup 50-100ms per module | High | [X] Bad |
| Import only essential modules in AppModule | Low (1-2 modules) | Minimal startup delay | Low | [OK] Good |
AppModule in a NestJS application?AppModule using the @Module decorator in NestJS?@Module decorator requires an object with properties like controllers and providers, and must decorate an exported class.@Module with an object and exports the class. Options B and D lack the decorator, and C misses export keyword.AppModule code, what will be the output when the app starts?import { Module } from '@nestjs/common';
import { CatsController } from './cats.controller';
import { CatsService } from './cats.service';
@Module({
controllers: [CatsController],
providers: [CatsService],
})
export class AppModule {}AppModule imports CatsController in controllers and CatsService in providers, so both are registered properly.AppModule code snippet:import { Module } from '@nestjs/common';
@Module({
controllers: CatsController,
providers: [CatsService],
})
export class AppModule {}controllers property must be an array, but here it is assigned a single value CatsController without brackets.UsersModule to your NestJS app. How should you modify the AppModule to include it properly?UsersModule are imported into the root module via the imports array to connect them.Pass the test and this pattern moves unknown