WEBVTT

1
00:00.590 --> 00:02.120
Hi everyone.

2
00:02.120 --> 00:05.780
Let's discuss about the health checks right here.

3
00:05.810 --> 00:06.410
Okay?

4
00:06.800 --> 00:09.350
Open a recipe and open the health checks.

5
00:10.190 --> 00:23.630
And actually, when you want to deploy the application, we usually use something called

6
00:23.660 --> 00:24.350
health checks.

7
00:24.860 --> 00:25.490
Okay.

8
00:26.000 --> 00:31.610
And actually I will show you the basic idea about health check, okay.

9
00:31.640 --> 00:32.930
Only the basic idea.

10
00:33.620 --> 00:41.480
And with the real health check in the real application, we usually use another tool.

11
00:42.950 --> 00:43.820
okay.

12
00:43.850 --> 00:47.780
And this job will be for the Devop person in your company.

13
00:48.050 --> 00:58.520
For that reason, right now we just use the the basic idea firstly in here, we will install the

14
00:58.520 --> 01:02.290
package called Nestjs terminus right here.

15
01:02.320 --> 01:02.890
Okay.

16
01:03.820 --> 01:04.300
Paste that

17
01:12.100 --> 01:18.250
And when it's all been installed right here, we can use the health check.

18
01:23.530 --> 01:24.280
Right here.

19
01:24.310 --> 01:30.790
We must create a new module for the health.

20
01:31.750 --> 01:35.920
Okay, let me let me create the new.

21
01:40.150 --> 01:40.570
Okay.

22
01:40.840 --> 01:43.990
After it's done, I will create a new module.

23
01:48.700 --> 01:49.870
Called health.

24
01:52.180 --> 01:58.690
And wait a bit. In the health, we must import  something called terminus module.

25
01:58.810 --> 02:00.930
And import that inside here.

26
02:01.050 --> 02:04.740
And we also need the controller to create the health check, right

27
02:05.250 --> 02:10.050
And you don't need to worry about what actually is inside the terminus.

28
02:10.200 --> 02:12.060
This is not important, right?

29
02:12.720 --> 02:22.110
Just make sure this is already a export somewhere and we can reuse that in our application.

30
02:23.640 --> 02:28.200
So let me create one more thing called controller also.

31
02:36.720 --> 02:43.290
And let's open src folder, open the health, removed some file.

32
02:43.290 --> 02:47.070
And inside the module right here let me import.

33
02:50.310 --> 02:53.280
We will import something called terminus module.

34
02:53.310 --> 02:58.950
Let me import that and import that  to the import statement right here.

35
02:59.790 --> 03:00.150
Okay.

36
03:00.180 --> 03:01.340
Now the first one.

37
03:03.620 --> 03:05.120
And the second one.

38
03:05.810 --> 03:07.370
What is the second one?

39
03:08.480 --> 03:12.410
We need to create a health check endpoint

40
03:12.440 --> 03:13.010
Right.

41
03:13.940 --> 03:23.690
And we will install this package also right here, http health indicator.

42
03:23.720 --> 03:29.720
require nestjs/axios. So please make sure install that. For that reason. I'll install that

43
03:36.500 --> 03:36.830
Okay.

44
03:36.860 --> 03:41.180
After install let me copy everything from the health controller here.

45
03:42.230 --> 03:47.390
I will go back and rename this one here health.

46
03:48.110 --> 03:48.530
Okay.

47
03:49.070 --> 03:58.670
Now in the @Get endpoint with the health check and with the check it will ping for me

48
03:58.700 --> 04:00.320
into something like that.

49
04:00.590 --> 04:07.400
Okay, let me show you what it means and how we can access itto the URL inside the Get.

50
04:07.430 --> 04:08.900
We will use the /health

51
04:08.930 --> 04:09.470
Right.

52
04:09.530 --> 04:11.420
So let me copy here.

53
04:12.560 --> 04:15.170
I will /health

54
04:16.070 --> 04:18.860
Oh sorry

55
04:21.650 --> 04:22.460
I think.

56
04:29.300 --> 04:33.830
Uh I think I typo around somewhere.

57
04:38.840 --> 04:40.850
Oh, we have some internal server error.

58
04:40.880 --> 04:45.350
Let me say, what is the terminal server inside?

59
04:46.070 --> 04:51.440
Uh, HTTPService not available in the current context.

60
04:51.530 --> 04:59.570
So for that reason I will go back to the here and we must import something called HTTP module right

61
04:59.590 --> 05:00.130
here.

62
05:00.550 --> 05:01.180
Right.

63
05:01.930 --> 05:04.420
Let me show.

64
05:07.330 --> 05:07.390
You.

65
05:09.850 --> 05:10.540
Let me show you.

66
05:11.020 --> 05:11.410
Okay.

67
05:11.830 --> 05:12.310
Right here.

68
05:13.750 --> 05:18.520
If we refresh now, you can see it has something called status.

69
05:18.550 --> 05:19.390
Okay.

70
05:19.420 --> 05:22.660
And the next docs, the status will be up

71
05:23.740 --> 05:24.460
So the up.

72
05:24.460 --> 05:28.960
It means this NestJS docs is also work, right?

73
05:29.050 --> 05:30.460
You can read more about them.

74
05:31.600 --> 05:34.450
Uh, for example, like this status.

75
05:34.450 --> 05:38.170
This is the what we want, right?

76
05:38.950 --> 05:42.640
So but. This will health check for the nestjs docs.

77
05:42.940 --> 05:54.430
We can use , for example, if I create one more thing you can say in the real world,

78
05:54.460 --> 05:59.140
in the real world application, the health check will much more than that.

79
05:59.170 --> 05:59.470
Okay.

80
05:59.500 --> 06:00.450
If you have many.

81
06:00.480 --> 06:00.960
many

82
06:01.410 --> 06:02.040
The health check

83
06:02.070 --> 06:02.460
Okay.

84
06:02.970 --> 06:05.280
Because this is just a simple project

85
06:05.910 --> 06:13.320
Let me click on TypeORM and we will pring the check to the database. Let see

86
06:15.390 --> 06:23.070
Actually this is the database right. We need.

87
06:23.100 --> 06:29.940
Import the private and inject the db into here

88
06:32.100 --> 06:33.090
We will apply.

89
06:33.090 --> 06:41.130
We will inject something called let me see. MongooseHealthIndicator

90
06:41.220 --> 06:46.380
Because we already we've been using the Mongo for that reason.

91
06:46.380 --> 06:49.800
We inject that and let me refresh over here.

92
06:53.040 --> 07:00.800
Now you will see we have one more thing called the database status will be "up", right?

93
07:00.830 --> 07:02.990
Let me remove the nestjs

94
07:03.020 --> 07:05.330
We don't need to care about us.

95
07:06.170 --> 07:06.650
Okay.

96
07:10.520 --> 07:10.970
Okay.

97
07:11.000 --> 07:13.220
Now, right now, we only have a database

98
07:13.760 --> 07:14.030
Okay.

99
07:14.060 --> 07:18.080
You can use something like that.

100
07:18.110 --> 07:22.970
And you can easily write more and more.

101
07:25.880 --> 07:26.600
About us.

102
07:26.690 --> 07:28.430
For example, like this.

103
07:28.790 --> 07:29.900
Or the memory.

104
07:30.770 --> 07:31.280
Okay.

105
07:33.080 --> 07:38.300
So we have so many things you can try to do that by your own. But.

106
07:39.290 --> 07:47.210
Remember when we work with Real project, you can see the different tools.

107
07:47.390 --> 07:50.330
Okay, to do the health check right here.

108
07:50.330 --> 07:52.910
And I just give you some idea.

109
07:53.510 --> 07:53.840
Okay.

110
07:53.870 --> 07:58.370
So that's it, that's for the video.

111
07:58.400 --> 07:59.960
I will see you in the next one.