All quizzesMedium
Namespaced Config & Hooks — Series 3
Preview — 3 of 10 questions
With DB_POOL_SIZE unset, what does database.poolSize become?
javascript
ConfigModule.forRoot({
validationSchema: Joi.object({ DB_POOL_SIZE: Joi.number().default(10) }),
load: [registerAs('database', () => ({ poolSize: Number(process.env.DB_POOL_SIZE ?? 20) }))],
});A10, because schema defaults take precedence over factory defaults
B20 — the factory reads process.env directly, and whether the schema's default has been written back to the environment is an implementation detail you should not depend on; keeping the default in exactly one place removes the ambiguity
CNaN, since neither default applies
DBoth are applied and the values are summed
What is the argument, and why is it useful?
javascript
@Injectable()
export class QueueService implements OnApplicationShutdown {
onApplicationShutdown(signal?: string) {
this.logger.log(`Shutting down after ${signal ?? 'programmatic close'}`);
}
}AThe exit code the process is about to return
BThe name of the module being destroyed
CThe number of milliseconds remaining in the grace period
DThe signal that triggered the shutdown — SIGTERM from an orchestrator, SIGINT from a local Ctrl-C — or undefined when app.close() was called directly; distinguishing them lets a deployment shutdown drain carefully while a local interrupt exits quickly
Which initialises first?
javascript
@Module({ imports: [CacheModule, SearchModule] })
export class AppModule {}
// both implement onModuleInitANeither order is guaranteed in a way you should depend on: Nest orders initialisation by the dependency graph, and two modules with no relationship between them have no defined relative order — if one genuinely needs the other ready, that dependency should be declared with an imports entry rather than inferred from position
BCacheModule, because it appears first in the array
CSearchModule, because initialisation walks the array in reverse
DBoth run concurrently, so either may finish first
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.