import databaseConfig from './config/database.config';
@Module({
imports: [
ConfigModule.forRoot({
load: [databaseConfig],
}),
],
})
export class AppModule {}
the registerAs has to be loaded into the configureModule.forRoot by adding it in the the load array.
This is valuable to ensure the registerAs is only applicable for the module only. It is better as most of the config is required for the respective modules only.
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import databaseConfig from './database.config';
@Module({
imports: [ConfigModule.forFeature(databaseConfig)],
providers: [],
exports: []
})
export class CouchdbModule { }
If I understand correctly, forRoot and forFeature are just convention. Because the instantiation is actually checks for the token which is based on the passed parameter (dbconfig in the sample). So if we use forRoot in two different modules with the same setting, we will still have 1 instance, the second forRoot call will receive the first instance. And if in a module we have 2 calls forRoot with different dbConfig, we will have 2 instances.
And forFeature on the other hand is intended to be using existing instance with additional option.