title: NestJs - ConfigModule.forRoot isGlobal not working
body: <p>I am trying to load the &quot;process.env.AUTH_SECRET&quot; in AuthModule, but it is giving me the undefined error &quot;Error: secretOrPrivateKey must have a value&quot;.</p>
  <p>I did setup the &quot;isGlobal: true&quot; in AppModule and it was able to read &quot;process.env.MONGO_URL&quot; there fine.</p>
  <p>I have also installed dotenv, which reads fine if I do:</p>
  <pre><code>import * as dotenv from 'dotenv';
  dotenv.config();
  
  export const jwtConstants = {
    secret: process.env.AUTH_SECRET,
  };
  
  </code></pre>
  <p>But I would rather do it the &quot;NestJs&quot; way as <a href="https://docs.nestjs.com/techniques/configuration" rel="nofollow noreferrer">the doc</a> says adding isGlobal should make the env available to all other modules.</p>
  <p>auth.module.ts</p>
  <pre><code>import { Module } from '@nestjs/common';
  import { AuthService } from './auth.service';
  import { UserModule } from '../user/user.module';
  import { PassportModule } from '@nestjs/passport';
  import { LocalStrategy } from './local.strategy';
  import { JwtModule } from '@nestjs/jwt';
  
  @Module({
    imports: [
      UserModule,
      PassportModule,
      JwtModule.register({
        secret: process.env.AUTH_SECRET, //Cannot read this.
        signOptions: { expiresIn: '60s' },
      }),
    ],
    providers: [AuthService, LocalStrategy],
    exports: [AuthService, JwtModule],
  })
  export class AuthModule {}
  
  </code></pre>
  <p>app.module.ts</p>
  <pre><code>import { Module } from '@nestjs/common';
  import { AppController } from './app.controller';
  import { AppService } from './app.service';
  import { UserModule } from './user/user.module';
  import { MongooseModule } from '@nestjs/mongoose';
  import { ConfigModule } from '@nestjs/config';
  import { AuthModule } from './auth/auth.module';
  
  @Module({
    imports: [
      ConfigModule.forRoot({
        isGlobal: true,
      }),
      UserModule,
      MongooseModule.forRoot(process.env.MONGO_URL), // Can read this fine
      AuthModule,
    ],
    controllers: [AppController],
    providers: [AppService],
  })
  export class AppModule {}
  
  </code></pre>
  <p>What am I missing or doing wrong? Just for reference, I am trying to follow this <a href="https://docs.nestjs.com/security/authentication" rel="nofollow noreferrer">authentication tutorial</a>.</p>
  <p>Thank you,</p>