Given a NestJS configuration service with namespaces, what will be the output of the following code?
const config = new ConfigService({ database: { host: 'localhost', port: 5432 } });
const host = config.get('database.host');
console.log(host);Think about how nested keys are accessed in configuration namespaces.
The get method supports dot notation to access nested properties. So database.host returns the string "localhost".
Choose the correct way to define a configuration namespace using registerAs in NestJS.
Remember that registerAs requires a name and a function returning the config object.
Option B correctly exports a constant assigned to registerAs with a name and a function returning the config object. Option B uses default export which is not typical. Option B misses the name argument. Option B passes an object instead of a function.
Consider two configuration namespaces merged in NestJS. What is the value of app.port after merging?
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);
Think about how object spread works when merging objects with overlapping keys.
The second object overrideConfig() overwrites the port key from the first. So the final port is 4000.
Given this code, why does config.get('database.password') return undefined?
const config = new ConfigService({ database: { user: 'admin' } });
const password = config.get('database.password');
console.log(password);Check if the key you are accessing exists in the config object.
The password key is missing from the database object, so accessing it returns undefined. Dot notation is supported, and the config object is not empty.
Choose the most accurate description of how configuration namespaces work in NestJS.
Think about the purpose of namespaces and how they affect config access.
Namespaces in NestJS group related configuration values and support dot notation for easy access. They do not automatically validate or flatten keys, nor do they prevent runtime changes by default.