Search code examples
typescriptpostgresqltypeorm

Unable to connect to TyreORM Module db using postgres docker image


I'm creating a NestJS Application and using TyeORM to connect with my local db. The local db is a postgres image running in background. I'm able to connect to that image using pgadmin, but getting the error attached in the image while starting the application.

This is the code that I've added for adding typeorm configuration:

@Module({
  imports: [
    TyreDetailsModule,
    TypeOrmModule.forRoot({
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      username: 'postgres',
      password: 'postgres',
      database: 'testDb',
      autoLoadEntities: true,
      synchronize: true,
    }),
  ],

Solution

  • Changing the host from localhost to 127.0.0.1 worked.