0
0
NestJSframework~10 mins

ConfigModule setup in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import ConfigModule globally in a NestJS module.

NestJS
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';

@Module({
  imports: [ConfigModule.[1]({ isGlobal: true })],
})
export class AppModule {}
Drag options to blanks, or click blank then click option'
AforRoot
Bregister
Ccreate
Dinitialize
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist on ConfigModule.
Forgetting to set isGlobal to true for global availability.
2fill in blank
medium

Complete the code to load a custom configuration file using ConfigModule.

NestJS
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import customConfig from './custom.config';

@Module({
  imports: [ConfigModule.forRoot({ [1]: [customConfig] })],
})
export class AppModule {}
Drag options to blanks, or click blank then click option'
AconfigFiles
Bfiles
Cimports
Dload
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect option names like 'files' or 'imports'.
Passing the configuration file directly without wrapping in an array.
3fill in blank
hard

Fix the error in the code to correctly inject ConfigService in a service constructor.

NestJS
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class MyService {
  constructor(private readonly [1]: ConfigService) {}
}
Drag options to blanks, or click blank then click option'
AconfigService
Bservice
CConfigService
Dconfig
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name as the parameter name.
Using generic or unclear parameter names.
4fill in blank
hard

Fill both blanks to create a configuration object with environment variables and default values.

NestJS
export default () => ({
  port: parseInt(process.env.[1] || '[2]', 10),
});
Drag options to blanks, or click blank then click option'
APORT
B3000
CNODE_PORT
D8080
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect environment variable names.
Not providing a string default value.
5fill in blank
hard

Fill all three blanks to access a nested configuration value safely using ConfigService.

NestJS
const dbHost = this.configService.get<string>('database.[1].[2]', [3]);
Drag options to blanks, or click blank then click option'
Aconnection
Bhost
C'localhost'
Dport
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect nested keys.
Using an options object instead of a positional default value.