0
0
NestJSframework~20 mins

Why configuration management matters in NestJS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Config Mastery in NestJS
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use configuration management in NestJS?
Which of the following best explains why configuration management is important in a NestJS application?
AIt automatically updates the application dependencies to the latest versions.
BIt compiles the NestJS application into a single executable file.
CIt allows the application to change settings without modifying code, making it easier to adapt to different environments.
DIt provides a graphical user interface for managing database records.
Attempts:
2 left
💡 Hint
Think about how apps behave differently in development, testing, and production.
component_behavior
intermediate
2:00remaining
Behavior of ConfigService in NestJS
What will be the output of the following code snippet when the environment variable PORT is set to 3000?
NestJS
import { ConfigService } from '@nestjs/config';

const configService = new ConfigService();
const port = configService.get('PORT');
console.log(port);
A3000
Bundefined
Cnull
DThrows an error because ConfigService is not injected
Attempts:
2 left
💡 Hint
ConfigService reads environment variables by default.
📝 Syntax
advanced
2:00remaining
Correct way to load configuration in NestJS
Which option correctly shows how to load a configuration file using ConfigModule in a NestJS application?
NestJS
import { ConfigModule } from '@nestjs/config';

@Module({
  imports: [
    // Which option is correct here?
  ],
})
export class AppModule {}
AConfigModule.forRoot({ envFilePath: '.env' })
BConfigModule.load('.env')
CConfigModule.forFeature('.env')
DConfigModule.register({ path: '.env' })
Attempts:
2 left
💡 Hint
Check the official method to load environment files in ConfigModule.
🔧 Debug
advanced
2:00remaining
Why does ConfigService return undefined?
Given this NestJS service code, why does configService.get('DATABASE_URL') return undefined? @Module({ imports: [ConfigModule.forRoot()], }) export class AppModule {} @Injectable() export class DatabaseService { constructor(private configService: ConfigService) {} getDatabaseUrl() { return this.configService.get('DATABASE_URL'); } }
AConfigService must be manually instantiated with new before use.
BThe environment variable DATABASE_URL is not set in the environment or .env file.
CConfigModule.forRoot() must be called with isGlobal: false to work.
DThe get method requires a second argument to specify a default value.
Attempts:
2 left
💡 Hint
Check if the environment variable exists where the app runs.
lifecycle
expert
3:00remaining
When is configuration loaded in NestJS lifecycle?
At what point in the NestJS application lifecycle is the configuration loaded and available via ConfigService?
ADuring the application bootstrap phase, before any modules are initialized.
BAfter all modules have been initialized and the application is listening.
COnly when the first service requests a configuration value.
DAfter the main controller handles its first request.
Attempts:
2 left
💡 Hint
Think about when environment variables must be ready for use.