0
0
NestJSframework~20 mins

ConfigModule setup in NestJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ConfigModule Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this ConfigModule setup code?
Consider this NestJS module setup using ConfigModule. What will be the value of configService.get('APP_NAME') inside AppService?
NestJS
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      load: [() => ({ APP_NAME: 'NestApp' })],
    }),
  ],
  providers: [
    {
      provide: 'APP_SERVICE',
      useFactory: (configService: ConfigService) => {
        return { appName: configService.get('APP_NAME') };
      },
      inject: [ConfigService],
    },
  ],
  exports: ['APP_SERVICE'],
})
export class AppModule {}
Anull
B'NestApp'
Cundefined
DThrows error: ConfigService not found
Attempts:
2 left
💡 Hint
Remember that ConfigModule.forRoot with isGlobal: true makes the config available everywhere.
📝 Syntax
intermediate
2:00remaining
Which option correctly imports ConfigModule with environment variable support?
You want to load environment variables from a custom file .env.dev using ConfigModule. Which code snippet correctly sets this up?
AConfigModule.forRoot({ envPath: '.env.dev' })
BConfigModule.forRoot({ envFile: '.env.dev' })
CConfigModule.forRoot({ envFilePath: '.env.dev' })
DConfigModule.forRoot({ envFilePaths: ['.env.dev'] })
Attempts:
2 left
💡 Hint
Check the exact property name for specifying environment file path in ConfigModule options.
🔧 Debug
advanced
3:00remaining
Why does ConfigService return undefined for a variable?
Given this setup, why does configService.get('DATABASE_URL') return undefined? Code: import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; @Module({ imports: [ConfigModule.forRoot()], }) export class AppModule {} And the environment file .env contains: DATABASE_URL=postgres://user:pass@localhost/db But configService.get('DATABASE_URL') returns undefined.
AConfigService requires manual injection to work
BConfigModule.forRoot() requires explicit envFilePath to load .env
CDATABASE_URL is not a valid environment variable name
DThe .env file is not in the root directory where the app runs
Attempts:
2 left
💡 Hint
Check where the app expects the .env file to be located.
state_output
advanced
2:30remaining
What is the output of this ConfigModule async setup?
Consider this async configuration setup for ConfigModule. What will configService.get('API_KEY') return? Code: import { Module } from '@nestjs/common'; import { ConfigModule, ConfigService } from '@nestjs/config'; @Module({ imports: [ ConfigModule.forRoot({ isGlobal: true, load: [async () => { return new Promise(resolve => { setTimeout(() => resolve({ API_KEY: '12345' }), 100); }); }], }), ], }) export class AppModule {}
Aundefined
B'12345'
CPromise { <pending> }
DThrows error: Async load not supported
Attempts:
2 left
💡 Hint
Check if ConfigModule supports async functions in load array.
🧠 Conceptual
expert
3:00remaining
Which option correctly explains ConfigModule global behavior?
You want to use ConfigService in multiple modules without importing ConfigModule repeatedly. Which statement about ConfigModule.forRoot({ isGlobal: true }) is true?
AIt registers ConfigModule once globally, so all modules can inject ConfigService without importing ConfigModule again
BIt requires importing ConfigModule in every module to access ConfigService despite isGlobal: true
CIt disables ConfigService injection to force manual config passing
DIt only works if ConfigModule is imported in the root module explicitly
Attempts:
2 left
💡 Hint
Think about what 'global' means in NestJS modules.