Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the TerminusModule in a NestJS module.
NestJS
import { Module } from '@nestjs/common'; import { [1] } from '@nestjs/terminus'; @Module({ imports: [[1]], }) export class AppModule {}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect module names like HealthModule or HealthCheckModule.
Forgetting to import the TerminusModule.
✗ Incorrect
The TerminusModule is the official NestJS module for health checks and must be imported to use Terminus features.
2fill in blank
mediumComplete the code to create a health check endpoint using Terminus in a controller.
NestJS
import { Controller, Get } from '@nestjs/common'; import { HealthCheck, HealthCheckService } from '@nestjs/terminus'; @Controller('health') export class HealthController { constructor(private health: HealthCheckService) {} @Get() @HealthCheck() check() { return this.health.[1]([]); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like run() or execute() which do not exist on HealthCheckService.
Forgetting to call the method as a function.
✗ Incorrect
The HealthCheckService provides a method called check() to run all registered health indicators.
3fill in blank
hardFix the error in the health indicator registration by completing the code.
NestJS
import { Injectable } from '@nestjs/common'; import { HealthIndicator, HealthIndicatorResult, HealthCheckError } from '@nestjs/terminus'; @Injectable() export class DiskHealthIndicator extends HealthIndicator { async isHealthy(key: string): Promise<HealthIndicatorResult> { const diskFree = 100; // pretend value const isHealthy = diskFree > 50; if (!isHealthy) { throw new HealthCheckError('Disk space too low', [1]); } return this.getStatus(key, isHealthy, { diskFree }); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing incomplete or incorrect status objects to HealthCheckError.
Omitting the third argument with details.
✗ Incorrect
The HealthCheckError requires the health indicator result object, which is returned by getStatus with the current health state and details.
4fill in blank
hardFill both blanks to add a memory health indicator to the health check controller.
NestJS
import { Controller, Get } from '@nestjs/common'; import { HealthCheck, HealthCheckService, [1] } from '@nestjs/terminus'; @Controller('health') export class HealthController { constructor( private health: HealthCheckService, private [2]: MemoryHealthIndicator ) {} @Get('memory') @HealthCheck() checkMemory() { return this.health.check([ () => this.[2].checkHeap('memory_heap'), ]); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class names like MemoryIndicator or MemoryCheck.
Mismatching the injected variable name and the class.
✗ Incorrect
MemoryHealthIndicator is the official class to check memory usage in Terminus and must be imported and injected with the same name.
5fill in blank
hardFill all three blanks to create a custom health indicator and register it in the health check controller.
NestJS
import { Injectable } from '@nestjs/common'; import { HealthIndicator, HealthIndicatorResult, HealthCheckError } from '@nestjs/terminus'; @Injectable() export class [1] extends HealthIndicator { async isHealthy(key: string): Promise<HealthIndicatorResult> { const serviceUp = true; // pretend check const isHealthy = serviceUp; if (!isHealthy) { throw new HealthCheckError('Service down', this.getStatus(key, isHealthy)); } return this.getStatus(key, isHealthy); } } import { Controller, Get } from '@nestjs/common'; import { HealthCheck, HealthCheckService } from '@nestjs/terminus'; @Controller('health') export class HealthController { constructor( private health: HealthCheckService, private [2]: [1] ) {} @Get('custom') @HealthCheck() checkCustom() { return this.health.check([ () => this.[2].isHealthy('custom_service'), ]); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent names between class and injected variable.
Calling wrong methods or using wrong variable names.
✗ Incorrect
The custom health indicator class is named CustomHealthIndicator, and the injected variable uses camelCase customHealthIndicator. The method isHealthy is called on the injected instance.