项目作者: nestjs

项目描述 :
Terminus module for Nest framework (node.js) :robot:
高级语言: TypeScript
项目地址: git://github.com/nestjs/terminus.git
创建时间: 2018-08-24T08:43:59Z
项目社区:https://github.com/nestjs/terminus

开源协议:MIT License

下载



Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.



@nestjs/terminus">@nestjs/terminus.svg" alt="NPM Version" />
@nestjs/terminus">@nestjs/terminus.svg" alt="Package License" />
@nestjs/terminus">@nestjs/terminus.svg" alt="NPM Downloads" />
Discord
Backers on Open Collective
Sponsors on Open Collective



Description

This module contains integrated healthchecks for Nest.

Installation

@nestjs/terminus integrates with a lot of cool technologies, such as typeorm, grpc, mongodb, and many more!
In case you have missed a dependency, @nestjs/terminus will throw an error and prompt you to install the required dependency.
So you will only install what is actually required!

  1. npm install --save @nestjs/terminus

Usage

  1. Import the Terminus module
  2. Make sure the additionally needed modules are available to (e.g. TypeOrmModule), in case you want to do Database Health Checks.
  1. // app.module.ts
  2. @Module({
  3. controllers: [HealthController],
  4. imports:[
  5. // Make sure TypeOrmModule is available in the module context
  6. TypeOrmModule.forRoot({ ... }),
  7. TerminusModule
  8. ],
  9. })
  10. export class HealthModule { }
  1. Setup your HealthController which executes your Health Check.
  1. // health.controller.ts
  2. @Controller('health')
  3. export class HealthController {
  4. constructor(
  5. private health: HealthCheckService,
  6. private db: TypeOrmHealthIndicator,
  7. ) {}
  8. @Get()
  9. @HealthCheck()
  10. readiness() {
  11. return this.health.check([
  12. async () => this.db.pingCheck('database', { timeout: 300 }),
  13. ]);
  14. }
  15. }

If everything is set up correctly, you can access the healthcheck on http://localhost:3000/health.

  1. {
  2. "status": "ok",
  3. "info": {
  4. "database": {
  5. "status": "up"
  6. }
  7. },
  8. "details": {
  9. "database": {
  10. "status": "up"
  11. }
  12. }
  13. }

For more information, see docs.
You can find more samples in the samples/ folder of this repository.

Contribute

In order to get started, first read through our Contributing guidelines.

Setup

Setup the development environment by following these instructions:

  1. Fork & Clone the repository
  2. Install the dependencies
  1. pnpm i
  2. pnpm dev

In order to test the library against a sample, simply go to a sample and run
pnpm start:dev

  1. cd sample/000-dogs-app
  2. pnpm start:dev

[!NOTE]
Once the library is rebuilt, the pnpm start:dev within a sample
needs to be restarted in order to pick up the changes.

Test

For unit testing run the following command:

  1. pnpm test

For e2e testing, a Docker Compose stack is required. Make sure
Docker is installed on your machine and run the following command.

  1. docker compose up -d
  2. pnpm test:e2e

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you’d like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.