I am trying to use the @nestjs/typeorm
module and using the async configuration. In my app.module.ts
I have the following:
@Module({
controllers: [
AppController,
],
exports: [ConfigModule],
imports: [
ConfigModule,
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (config: ConfigService) => {
console.log("config.getPostgresConfig(): ", config.getPostgresConfig());
return {
...config.getPostgresConfig(),
entities,
synchronize: true,
type: "postgres",
} as PostgresConnectionOptions;
},
}),
],
providers: [AppService],
})
export class AppModule {}
The console.log prints the correct stuff, but I constantly get this error:
2019-06-17T14:41:35.569358700Z [Nest] 45 - 06/17/2019, 2:41 PM [NestFactory] Starting Nest application...
2019-06-17T14:39:31.277686600Z at Object.next (/root/node_modules/tslib/tslib.js:114:57)
2019-06-17T14:41:35.740192700Z [Nest] 45 - 06/17/2019, 2:41 PM [TypeOrmModule] Unable to connect to the database. Retrying (1)... +170ms
2019-06-17T14:41:35.740666500Z Error: No connection options were found in any of configurations file.
2019-06-17T14:41:35.740704100Z at ConnectionOptionsReader.<anonymous> (/root/src/connection/ConnectionOptionsReader.ts:41:19)
The config should be done all dynamically through the config service, I don't understand why it is asking for a config file, and why it can't connect to the database.