0
0
NestJSframework~30 mins

Health checks (Terminus) in NestJS - Mini Project: Build & Apply

Choose your learning style9 modes available
Health Checks with Terminus in NestJS
📖 Scenario: You are building a simple NestJS server that needs to report its health status. This is important for monitoring and ensuring the server is running well.
🎯 Goal: Create a health check endpoint using Terminus in NestJS that reports the server is healthy.
📋 What You'll Learn
Create a health check controller
Configure Terminus health check module
Implement a basic health check returning 'ok' status
Expose the health check endpoint at '/health'
💡 Why This Matters
🌍 Real World
Health checks help monitor if your server and its dependencies are working well. This is important for uptime and reliability.
💼 Career
Many companies use health checks in their backend services to integrate with monitoring tools and orchestrators like Kubernetes.
Progress0 / 4 steps
1
Setup Health Check Controller
Create a controller called HealthController with a route /health that will later return health status.
NestJS
Need a hint?

Use @Controller('health') to set the route and @Get() for the GET method.

2
Add Terminus Health Module
Import TerminusModule from @nestjs/terminus and add it to the imports array of your main application module called AppModule.
NestJS
Need a hint?

Remember to import TerminusModule and add it to the imports array in @Module.

3
Use Terminus Health Check Service
Inject HealthCheckService and HttpHealthIndicator into HealthController. Use HealthCheckService.check() with HttpHealthIndicator.pingCheck('nestjs-docs', 'https://docs.nestjs.com') inside the check() method to perform a real health check.
NestJS
Need a hint?

Use dependency injection in the constructor and call this.health.check() with this.http.pingCheck() inside the check() method.

4
Complete and Test Health Endpoint
Ensure the HealthController and AppModule are correctly set up with Terminus. The health check endpoint should be accessible at /health and return JSON with the status of the ping check.
NestJS
Need a hint?

Review all previous steps and ensure the health check endpoint is fully implemented and the module imports are correct.