Hello! I am trying to implement some configuration files of the env variables in a custom way but it generates some conflicts. I would appreciate a hand.
What I did is the following:
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
envFilePath: environments[process.env.NODE_ENV],
load: [EnvConfig],
}),
// Here some modules...
],
providers: [],
})
export class AppModule {}
I have a configuration file like this:
import { registerAs } from '@nestjs/config';
export default registerAs('EnvConfig', () => {
return {
API: {
PORT: +process.env.PORT,
TIMEOUT_REQUEST: +process.env.TIMEOUT_REQUEST,
},
DATABASE: {
POSTGRESQL_HOST: process.env.POSTGRESQL_HOST,
POSTGRESQL_NAME: process.env.POSTGRESQL_NAME,
POSTGRESQL_PASSWORD: process.env.POSTGRESQL_PASSWORD,
POSTGRESQL_PORT: process.env.POSTGRESQL_PORT,
POSTGRESQL_USERNAME: process.env.POSTGRESQL_USERNAME,
POSTGRESQL_SSL: process.env.POSTGRESQL_SSL,
},
};
});
My idea is to be able to access environment variables in this way, as an object. However, how can I implement this in services or providers? I tried to do it for a custom typeorm provider but it generates an error (I will leave the error at the end, first I will show you the database provider).
database.module.ts
@Module({
imports: [
TypeOrmModule.forRootAsync({
imports: [
ConfigModule.forRoot({
load: [EnvConfig],
}),
],
useFactory: createDatabaseOptions,
}),
],
exports: [TypeOrmModule],
})
export class DatabaseModule {}
database.provider.ts
The database provider is attached in the image
The error is in an attached picture too