Complete the code to import ConfigModule asynchronously.
import { ConfigModule } from '@nestjs/config'; @Module({ imports: [ConfigModule.[1]({ isGlobal: true, })], }) export class AppModule {}
The forRootAsync method is used to configure modules asynchronously in NestJS.
Complete the code to provide a factory function for async config.
ConfigModule.forRootAsync({
useFactory: async () => {
const config = await fetchConfig();
return [1];
},
}),The factory function should return the config object directly.
Fix the error in the async config provider by completing the inject array.
ConfigModule.forRootAsync({
imports: [HttpModule],
useFactory: async (httpService: HttpService) => {
const response = await httpService.get('url').toPromise();
return response.data;
},
inject: [[1]],
}),The inject array must list the provider tokens to inject, here HttpService.
Fill both blanks to create an async config that uses a class provider.
ConfigModule.forRootAsync({
useClass: [1],
imports: [[2]],
}),The useClass option expects a class like ConfigService, and HttpModule is imported for HTTP features.
Fill all three blanks to create a complete async config with useFactory, inject, and imports.
ConfigModule.forRootAsync({
imports: [[1]],
useFactory: async (configService: [2]) => {
const settings = await configService.loadSettings();
return settings;
},
inject: [[3]],
}),Import HttpModule for HTTP features, inject ConfigService to use in the factory function.