notiz-dev / nestjs-prisma-starter

Starter template for NestJS 😻 includes GraphQL with Prisma Client, Passport-JWT authentication, Swagger Api and Docker
MIT License
2.37k stars 336 forks source link

Generate config object when initializing AppModule #490

Open mi-373 opened 4 months ago

mi-373 commented 4 months ago

Problem

If I try to use environment value like port: parseInt(process.env.PORT, 10) || 3000, instead of hard coded values, current implementation doesn't get correct value from .env.

Solution

I moved config object into function, now the config object will be generated on ConfigModule.forRoot({ isGlobal: true, load: [config] }) and we can get values from .env if we want.

source: https://docs.nestjs.com/techniques/configuration#custom-configuration-files