Sarath S
Sarath S

Reputation: 21

the value of the env file is not getting in the configuration file in nest js

My problem is I created a nest js application in this app I created a configuration file as per the reference of the official docs of nest js here we are providing the process.env.Port .....etc

but the process.env values are undefined How can I solve it I want to know why it is happening and What are the steps for doing this`

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { GraphQLModule } from '@nestjs/graphql';
import { MongooseModule } from '@nestjs/mongoose';
import { join } from 'path';
import { config } from 'src/config/configuration';

@Module({
  // imports: [ GraphQLModule.forRoot({
  //   autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
  // })],
  imports:[ConfigModule.forRoot({
    cache:true,
    isGlobal:true,
    load:[config]
  })],
  controllers: [],
  providers: [], 
})
this is app.module.ts
import { ConfigProps } from "src/interfaces/config.interfaces";

export const config = ():ConfigProps => ({
  port: parseInt(process.env.PORT, 10) || 3000,
  api: {
    apiUrl: process.env.API_URL,
    httpTimeout: 1000,
  },
  mongodb: {
    database: {
      connectionString: process.env.MONGODB_CONNECTION_STRING || 'mongodb://localhost:27017',
      databaseName: process.env.NODE_ENV || 'local'
    }
  }
 }); 
configuration file

Upvotes: 0

Views: 28

Answers (1)

Andrey Yankovich
Andrey Yankovich

Reputation: 331

please show your .env file, maybe wrong file name

Upvotes: 0

Related Questions