@@ -58,6 +58,14 @@ $ nest g controller health
58
58
59
59
Once we have installed ` @nestjs/terminus ` , imported our ` TerminusModule ` and created a new controller, we are ready to create a health check.
60
60
61
+ The ` HTTPHealthIndicator ` requires the ` @nestjs/axios ` package so make sure to have it installed:
62
+
63
+ ``` bash
64
+ $ npm i --save @nestjs/axios
65
+ ```
66
+
67
+ Now we can setup our ` HealthController ` :
68
+
61
69
``` typescript
62
70
@@filename (health .controller )
63
71
import { Controller , Get } from ' @nestjs/common' ;
@@ -104,27 +112,27 @@ export class HealthController {
104
112
@@filename (health .module )
105
113
import { Module } from ' @nestjs/common' ;
106
114
import { TerminusModule } from ' @nestjs/terminus' ;
115
+ import { HttpModule } from ' @nestjs/axios' ;
107
116
import { HealthController } from ' ./health.controller' ;
108
117
109
118
@Module ({
110
- imports: [TerminusModule ],
119
+ imports: [TerminusModule , HttpModule ],
111
120
controllers: [HealthController ],
112
121
})
113
122
export class HealthModule {}
114
123
@@switch
115
124
import { Module } from ' @nestjs/common' ;
116
125
import { TerminusModule } from ' @nestjs/terminus' ;
126
+ import { HttpModule } from ' @nestjs/axios' ;
117
127
import { HealthController } from ' ./health.controller' ;
118
128
119
129
@Module ({
120
- imports: [TerminusModule ],
130
+ imports: [TerminusModule , HttpModule ],
121
131
controllers: [HealthController ],
122
132
})
123
133
export class HealthModule {}
124
134
```
125
135
126
- > warning ** Warning** ` HttpHealthIndicator ` requires the installation of the ` @nestjs/axios ` package and the import of ` HttpModule ` .
127
-
128
136
Our health check will now send a _ GET_ -request to the ` https://docs.nestjs.com ` address. If
129
137
we get a healthy response from that address, our route at ` http://localhost:3000/health ` will return
130
138
the following object with a 200 status code.
0 commit comments