Currently, I am developing a NestJS application that interacts with a postgres database using TypeORM. During the development phase (npm run start:debug
), everything functions perfectly. However, when I proceed to build the application with npm run build
and attempt to run it via node /dist/main.js
, I encounter an error preventing the application from starting:
error: password authentication failed for user "(my system user name)"
at Parser.parseErrorMessage (/home/(my system user name)/application/node_modules/pg-protocol/dist/parser.js:287:98)
The implementation in my app.module file is quite basic:
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
...
import { ConfigModule } from '@nestjs/config';
@Module({
imports: [
TypeOrmModule.forRoot(),
...
ConfigModule.forRoot({
isGlobal: true,
}),
],
controllers: [],
providers: [],
})
export class AppModule {}
The TypeORM configuration details are stored in an .env
file, which I also copy to the dist
folder after building. Despite spending several days attempting to fix this issue, I have not been able to get it working properly in both development and production modes - even considering alternatives to utilizing an .env
file as long as it ensures functionality across both environments. Any suggestions on why the configuration settings are not being recognized in production?
Edit: I have experimented with various other configuration methods as outlined in NestJS setup TypeOrm connection with .env and @nestjs/config, for instance. While some options showed promise during development, none were successful when deployed in a production build.