0
0
NestJSframework~20 mins

Configuration namespaces in NestJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Configuration Namespace Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
What is the output of accessing a nested configuration namespace?

Given a NestJS configuration service with namespaces, what will be the output of the following code?

NestJS
const config = new ConfigService({ database: { host: 'localhost', port: 5432 } });
const host = config.get('database.host');
console.log(host);
Aundefined
B"database.host"
C"localhost"
DThrows an error
Attempts:
2 left
💡 Hint

Think about how nested keys are accessed in configuration namespaces.

📝 Syntax
intermediate
1:30remaining
Which option correctly defines a configuration namespace in NestJS?

Choose the correct way to define a configuration namespace using registerAs in NestJS.

AregisterAs('database', { host: 'localhost', port: 5432 });
Bexport const database = registerAs('database', () => ({ host: 'localhost', port: 5432 }));
Cexport const database = registerAs(() => ({ host: 'localhost', port: 5432 }));
Dexport default registerAs('database', () => ({ host: 'localhost', port: 5432 }));
Attempts:
2 left
💡 Hint

Remember that registerAs requires a name and a function returning the config object.

state_output
advanced
2:00remaining
What is the value of a nested config key after merging multiple namespaces?

Consider two configuration namespaces merged in NestJS. What is the value of app.port after merging?

NestJS
const appConfig = registerAs('app', () => ({ port: 3000, debug: true }));
const overrideConfig = registerAs('app', () => ({ port: 4000 }));

const configService = new ConfigService({
  ...appConfig(),
  ...overrideConfig()
});

const port = configService.get('port');
console.log(port);
A4000
B3000
Cundefined
DThrows an error
Attempts:
2 left
💡 Hint

Think about how object spread works when merging objects with overlapping keys.

🔧 Debug
advanced
2:00remaining
Why does accessing a nested config key return undefined?

Given this code, why does config.get('database.password') return undefined?

NestJS
const config = new ConfigService({ database: { user: 'admin' } });
const password = config.get('database.password');
console.log(password);
ABecause the config object is empty
BBecause dot notation is not supported in get method
CBecause ConfigService requires explicit schema for nested keys
DBecause 'password' key does not exist in the 'database' namespace
Attempts:
2 left
💡 Hint

Check if the key you are accessing exists in the config object.

🧠 Conceptual
expert
2:30remaining
Which statement best describes configuration namespaces in NestJS?

Choose the most accurate description of how configuration namespaces work in NestJS.

ANamespaces group related config values and allow dot notation access, improving organization and type safety.
BNamespaces automatically validate config values against a schema without extra setup.
CNamespaces flatten all config keys into a single level object for easier access.
DNamespaces prevent any runtime changes to configuration values once loaded.
Attempts:
2 left
💡 Hint

Think about the purpose of namespaces and how they affect config access.