Guilherme Gonzalez
Guilherme Gonzalez

Reputation: 61

Nestjs [Typeorm] Unable to connect to the database, connect ETIMEDOUT

I have a problem with the typeorm, it doesn't want to connect to my database, I have another project in exactly the same configuration pattern, and it connects normally to the database. I believe it is something with regard to the environment variables, because when putting the same variables in the other project it also gave the same error, but what is strange is that I can access the database normally through mysql workbench, what am I doing wrong ?

@nestjs/typeorm v8.0.3

mysql2 v2.3.3

typeorm v0.2.43

config.service.js

class ConfigService {
   constructor() { }
   public getTypeOrmConfig(): TypeOrmModuleOptions {
       return {
         type: 'mysql',
         host: process.env.DB_HOST,
         port: parseInt(process.env.DB_PORT),
         username: process.env.DB_USER,
         password: process.env.DB_PASS,
         database: process.env.DB_DATABASE,
         synchronize: false,
         autoLoadEntities: true,
         dropSchema: false
       }
     }

   }

   const configService = new ConfigService();
   export { configService };

main.module.ts

@Module({
     imports: [
       ConfigModule.forRoot(),
       TypeOrmModule.forRoot(configService.getTypeOrmConfig()),
       AuthModule,
       UsuarioModule,
       CargoModule,
       ContentfulModule
     ],
     controllers: [],
     providers: [],
   })
   export class MainModule { }

And my main.ts main.ts

Upvotes: 0

Views: 740

Answers (1)

Guilherme Gonzalez
Guilherme Gonzalez

Reputation: 61

I solved this using a local database, but i keep not knowing what caused this.

Upvotes: 0

Related Questions