0
0
NestJSframework~10 mins

Environment-based configuration 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 the ConfigModule in a NestJS module.

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

@Module({
  imports: [ConfigModule.[1]()],
})
export class AppModule {}
Drag options to blanks, or click blank then click option'
AforRoot
Bregister
Cinitialize
Dsetup
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist on ConfigModule.
Forgetting to call the method as a function.
2fill in blank
medium

Complete the code to inject ConfigService into a service constructor.

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

@Injectable()
export class AppService {
  constructor(private readonly [1]: ConfigService) {}
}
Drag options to blanks, or click blank then click option'
Aconfig
BconfigSrv
CserviceConfig
DconfigService
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic or unclear variable name.
Not matching the injected type with the variable name.
3fill in blank
hard

Fix the error in accessing an environment variable using ConfigService.

NestJS
const port = this.configService.[1]('PORT');
Drag options to blanks, or click blank then click option'
AgetValue
Bget
Cfetch
Dretrieve
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like getValue or fetch.
Trying to access environment variables directly without ConfigService.
4fill in blank
hard

Fill in the blank to access an environment variable with a default value fallback.

NestJS
const dbHost = this.configService.[1]('DATABASE_HOST', 'localhost');
Drag options to blanks, or click blank then click option'
Aget
Bdefault
Cundefined
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names.
Trying to use keywords like undefined or null as default values incorrectly.
5fill in blank
hard

Fill all three blanks to define a custom configuration loader function.

NestJS
import { [1] } from '@nestjs/config';

export const customConfig = registerAs([2], () => ({
  port: parseInt(process.env.[3] || '3000', 10),
}));
Drag options to blanks, or click blank then click option'
AregisterAs
Bconfig
CPORT
DConfigModule
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing import names.
Using wrong environment variable names.
Not wrapping the config in a function.