# Health checks

We may use **Terminus** to check the health of our components. It offers a set of **health indicators**, in order to confirm the overall health of the system. Let's then check the **database health**.

First, we should install the necessary dependency.

```sh
yarn add @nestjs/terminus
```

Now, create a resource for **health** with <mark style="color:red;">no</mark> CRUD, and inside the module import the <mark style="color:blue;">`TerminusModule`</mark>.

```sh
nest g res health
```

In the controller, create a route for performing the health check. It should be a **public** route.

```typescript
@HealthCheck()
@Public()
@Get()
check() {
  return this.healthService.check();
}
```

{% hint style="info" %}
Note the <mark style="color:blue;">`@HealthCheck()`</mark> decorator, which will make this route:

* Be documented by **Swagger**
* <mark style="color:red;">Not</mark> be cached
  {% endhint %}

Then, in the service, inject the <mark style="color:blue;">`HealthCheckService`</mark> and the <mark style="color:blue;">`TypeOrmHealthIndicator`</mark>.

```typescript
private readonly health: HealthCheckService,
private readonly database: TypeOrmHealthIndicator,
```

Finally, we should use the <mark style="color:blue;">`HealthCheckService`</mark> to determine the **overall health**, passing to it all the indicators we want. In this case, it will be just the database indicator.

```typescript
check() {
  return this.health.check([() => this.database.pingCheck('database')]);
}
```

> If you want to add more indicators, this [NestJS doc](https://docs.nestjs.com/recipes/terminus) shows all the available options, and examples of how to use some of them.

<mark style="color:green;">**Commit**</mark> - Adding health check
