NestJS · Junior · Question 74 of 75
Why use TypeOrmModule.forRootAsync({ useFactory, inject: [ConfigService] }) instead of forRoot({...})?
- 1
forRootis deprecated and removed - 2
forRootAsyncconnects to several databases at once - ✓Correct answer: The connection options can then come from injected services like
ConfigServiceinstead of being hard-coded
Explanation
Async configuration is a common pattern for dynamic modules: the factory runs after its dependencies are ready.