Hi everyone.
Let's discuss about the health checks right here.
Okay?
Open a recipe and open the health checks.
And actually, when you want to deploy the application, we usually use something called
health checks.
Okay.
And actually I will show you the basic idea about health check, okay.
Only the basic idea.
And with the real health check in the real application, we usually use another tool.
okay.
And this job will be for the Devop person in your company.
For that reason, right now we just use the the basic idea firstly in here, we will install the
package called Nestjs terminus right here.
Okay.
Paste that
And when it's all been installed right here, we can use the health check.
Right here.
We must create a new module for the health.
Okay, let me let me create the new.
Okay.
After it's done, I will create a new module.
Called health.
And wait a bit. In the health, we must import something called terminus module.
And import that inside here.
And we also need the controller to create the health check, right
And you don't need to worry about what actually is inside the terminus.
This is not important, right?
Just make sure this is already a export somewhere and we can reuse that in our application.
So let me create one more thing called controller also.
And let's open src folder, open the health, removed some file.
And inside the module right here let me import.
We will import something called terminus module.
Let me import that and import that to the import statement right here.
Okay.
Now the first one.
And the second one.
What is the second one?
We need to create a health check endpoint
Right.
And we will install this package also right here, http health indicator.
require nestjs/axios. So please make sure install that. For that reason. I'll install that
Okay.
After install let me copy everything from the health controller here.
I will go back and rename this one here health.
Okay.
Now in the @Get endpoint with the health check and with the check it will ping for me
into something like that.
Okay, let me show you what it means and how we can access itto the URL inside the Get.
We will use the /health
Right.
So let me copy here.
I will /health
Oh sorry
I think.
Uh I think I typo around somewhere.
Oh, we have some internal server error.
Let me say, what is the terminal server inside?
Uh, HTTPService not available in the current context.
So for that reason I will go back to the here and we must import something called HTTP module right
here.
Right.
Let me show.
You.
Let me show you.
Okay.
Right here.
If we refresh now, you can see it has something called status.
Okay.
And the next docs, the status will be up
So the up.
It means this NestJS docs is also work, right?
You can read more about them.
Uh, for example, like this status.
This is the what we want, right?
So but. This will health check for the nestjs docs.
We can use , for example, if I create one more thing you can say in the real world,
in the real world application, the health check will much more than that.
Okay.
If you have many.
many
The health check
Okay.
Because this is just a simple project
Let me click on TypeORM and we will pring the check to the database. Let see
Actually this is the database right. We need.
Import the private and inject the db into here
We will apply.
We will inject something called let me see. MongooseHealthIndicator
Because we already we've been using the Mongo for that reason.
We inject that and let me refresh over here.
Now you will see we have one more thing called the database status will be "up", right?
Let me remove the nestjs
We don't need to care about us.
Okay.
Now, right now, we only have a database
Okay.
You can use something like that.
And you can easily write more and more.
About us.
For example, like this.
Or the memory.
Okay.
So we have so many things you can try to do that by your own. But.
Remember when we work with Real project, you can see the different tools.
Okay, to do the health check right here.
And I just give you some idea.
Okay.
So that's it, that's for the video.
I will see you in the next one.