Challenge - 5 Problems
Terminus Health Check Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this NestJS Terminus health check controller?
Consider this health check controller using Terminus in NestJS. What will the HTTP response body be when the /health endpoint is called?
NestJS
import { Controller, Get } from '@nestjs/common'; import { HealthCheck, HealthCheckService, HttpHealthIndicator } from '@nestjs/terminus'; @Controller('health') export class HealthController { constructor( private health: HealthCheckService, private http: HttpHealthIndicator, ) {} @Get() @HealthCheck() check() { return this.health.check([ () => this.http.pingCheck('nestjs-docs', 'https://docs.nestjs.com'), ]); } }
Attempts:
2 left
💡 Hint
The pingCheck returns status 'up' if the URL is reachable.
✗ Incorrect
The HealthCheckService returns a JSON with status 'ok' if all checks pass. The pingCheck to 'https://docs.nestjs.com' will succeed, so the status is 'up'.
📝 Syntax
intermediate2:00remaining
Which option causes a syntax error in this NestJS Terminus health check setup?
Identify which code snippet will cause a syntax error when defining a health check method in a NestJS controller using Terminus.
Attempts:
2 left
💡 Hint
Check if the decorator is properly called as a function.
✗ Incorrect
The @HealthCheck decorator must be called with parentheses even if no arguments are passed. Omitting () causes a syntax error.
❓ state_output
advanced2:00remaining
What is the value of the 'status' field when a database health check fails?
Given this health check method in NestJS Terminus, what will be the 'status' field in the JSON response if the database ping fails?
NestJS
import { Controller, Get } from '@nestjs/common'; import { HealthCheck, HealthCheckService, TypeOrmHealthIndicator } from '@nestjs/terminus'; @Controller('health') export class HealthController { constructor( private health: HealthCheckService, private db: TypeOrmHealthIndicator, ) {} @Get() @HealthCheck() check() { return this.health.check([ () => this.db.pingCheck('database'), ]); } }
Attempts:
2 left
💡 Hint
The overall status is 'error' if any check fails.
✗ Incorrect
If the database pingCheck fails, Terminus sets the overall status to 'error' in the response JSON.
🔧 Debug
advanced2:00remaining
Why does this Terminus health check always return status 'error'?
This health check always returns status 'error' even though the URL is correct. What is the likely cause?
NestJS
import { Controller, Get } from '@nestjs/common'; import { HealthCheck, HealthCheckService, HttpHealthIndicator } from '@nestjs/terminus'; @Controller('health') export class HealthController { constructor( private health: HealthCheckService, private http: HttpHealthIndicator, ) {} @Get() @HealthCheck() check() { return this.health.check([ () => this.http.pingCheck('nestjs-docs', 'https://docs.nestjs.com'), () => this.http.pingCheck('invalid-url', 'htp://invalid-url'), ]); } }
Attempts:
2 left
💡 Hint
Check the URLs passed to pingCheck carefully.
✗ Incorrect
The second pingCheck uses 'htp://' instead of 'http://', causing that check to fail and the overall status to be 'error'.
🧠 Conceptual
expert3:00remaining
Which option best describes how Terminus aggregates multiple health indicators?
In NestJS Terminus, when multiple health indicators are passed to HealthCheckService.check(), how is the overall health status determined?
Attempts:
2 left
💡 Hint
Think about how a system health check should behave if one part fails.
✗ Incorrect
Terminus returns 'ok' only if all health indicators are 'up'. If any indicator fails (returns 'down'), the overall status is 'error'.