NestJS health check library.
- Check backend application is running
- Optionally use TypeOrmHealthIndicator to ping default database that uses TypeORM
- Optionally check that redis is set up
- Optionally checl that bull queue is connect to redis and ready to accept jobs
- Provide custom indicator functions to execute
- Define /health endpoint to carry health check and output response
$ npm install nestjs-health
import { HealthModule } from 'nestjs-health';
@Module({
HealthModule.forRoot({
app: 'nestjs-health-terminus',
backendUrl: 'http://localhost:3000',
shouldCheckDatabase: true,
queueNames: ['fibonacci', 'prime'],
redisOptions: {
host: 'localhost',
port: 6379,
},
})
})
export class AppModule {}
import { HealthModule } from 'nestjs-health';
@Module({
HealthModule.forRootAsync({
inject: [ConfigService, HttpHealthIndicator],
useFactory: (configService: ConfigService, http: HttpHealthIndicator) => {
return {
app: 'nestjs-health-terminus',
backendUrl: configService.get<string>('BACKEND_DOMAIN', ''),
shouldCheckDatabase: true,
queueNames: ['fibonacci', 'prime'],
redisOptions: {
host: configService.get<string>('REDIS_HOST', 'localhost'),
port: configService.get<number>('REDIS_PORT', 0),
},
indicatorFunctions: [
() => http.pingCheck('nestjs-docs', 'https://docs.nestjs.com'),
() => http.pingCheck('angular-docs', 'https://angular.io/docs'),
],
};
},
});
})
export class AppModule {}
// http://localhost:3000/health
{
"status": "ok",
"info": {
"nestjs-health-terminus": {
"status": "up"
},
"database": {
"status": "up"
},
"redis": {
"status": "up"
},
"bull": {
"status": "up"
},
"nestjs-docs": {
"status": "up"
},
"angular-docs": {
"status": "up"
}
},
"error": {},
"details": {
"nestjs-health-terminus": {
"status": "up"
},
"database": {
"status": "up"
},
"redis": {
"status": "up"
},
"bull": {
"status": "up"
},
"nestjs-docs": {
"status": "up"
},
"angular-docs": {
"status": "up"
}
}
}