nestjstypeormnestjs-typeormjhipster-blueprint

unable to connect to Postgress SQL through Nhipster generated code


I am using Nhipster, a NodeJS based application generator for Jhipster. The application generated and loaded fine the only problem I am facing is connecting to database. Below is the code snippet I have used to connect to the database in the file server\src\orm.config.ts.

   else if (process.env.BACKEND_ENV === 'dev') {
    ormconfig = {
      name: 'default',
      type: 'postgres',
      // typeorm fails to auto load driver due to workspaces resolution
      driver: require('sqlite3'),
      database: 'judiciary',
      host: '127.0.0.1',
      port: 5432,
      username: 'postgres',
      password: 'root321',
      logging: true,
    };
  } 

The error I am getting is

[application] [Nest] 8164  - 04/06/2025, 12:43:56 pm   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
[application] TypeError: this.postgres.Pool is not a constructor
[application]     at PostgresDriver.createPool (D:\dev\judiciary\node_modules\typeorm\src\driver\postgres\PostgresDriver.ts:1507:22)       
[application]     at PostgresDriver.connect (D:\dev\judiciary\node_modules\typeorm\src\driver\postgres\PostgresDriver.ts:357:38)
[application]     at DataSource.initialize (D:\dev\judiciary\node_modules\src\data-source\DataSource.ts:253:27)
[application]     at D:\dev\judiciary\node_modules\@nestjs\typeorm\dist\typeorm-core.module.js:189:30
[application] [Nest] 8164  - 04/06/2025, 12:43:56 pm     LOG [InstanceLoader] JwtModule dependencies initialized +3ms
[application] [Nest] 8164  - 04/06/2025, 12:43:56 pm     LOG [InstanceLoader] ServeStaticModule dependencies initialized +1ms

Then I created a sample nest js applicatin and tried to connected to the database which is working fine. Below are the entries I made in app.module.ts

imports: [
    TypeOrmModule.forRoot({
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      password: 'root321',
      username: 'postgres',
      entities: [],
      database: 'sample',
      synchronize: true,
      logging: true,
    }),
    
  ],

Result

[Nest] 14120  - 04/06/2025, 12:42:13 pm     LOG [InstanceLoader] AppModule dependencies initialized +2ms
query: SELECT version()
query: SELECT * FROM current_schema()
query: START TRANSACTION
query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = 'public' AND "table_name" = 'typeorm_metadata'
query: COMMIT

But I am not sure why the application is not getting connected through Nhipster generated application. Any directions please.


Solution

  • You say that you're trying to attach to a postgres database, but telling TypeORM to use the driver for sqlite3. These are not perfectly compatible databases. Remove the driver and everything should be fine