πŸ“¦ nestjs / terminus

Terminus module for Nest framework (node.js) :robot:

β˜… 727 stars β‘‚ 110 forks πŸ‘ 727 watching βš–οΈ MIT License
javascriptnestnestjsnodenodejstypescript
πŸ“₯ Clone https://github.com/nestjs/terminus.git
HTTPS git clone https://github.com/nestjs/terminus.git
SSH git clone git@github.com:nestjs/terminus.git
CLI gh repo clone nestjs/terminus
Livio Brunner Livio Brunner Merge pull request #2677 from nestjs/fix/e2e 23d9106 4 months ago πŸ“ History
πŸ“‚ master View all commits β†’
πŸ“ .github
πŸ“ .husky
πŸ“ e2e
πŸ“ lib
πŸ“ sample
πŸ“ tools
πŸ“„ .eslintignore
πŸ“„ .gitignore
πŸ“„ .npmignore
πŸ“„ .npmrc
πŸ“„ .nvmrc
πŸ“„ .prettierignore
πŸ“„ .release-it.json
πŸ“„ CHANGELOG.md
πŸ“„ CONTRIBUTING.md
πŸ“„ index.d.ts
πŸ“„ index.js
πŸ“„ index.ts
πŸ“„ LICENSE
πŸ“„ nest-cli.json
πŸ“„ package.json
πŸ“„ pnpm-lock.yaml
πŸ“„ README.md
πŸ“„ tsconfig.json
πŸ“„ README.md

Nest Logo

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

NPM Version Package License 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!

npm install --save @nestjs/terminus

Usage

  • Import the Terminus module
  • Make sure the additionally needed modules are available to (e.g. TypeOrmModule), in case you want to do Database Health Checks.
// app.module.ts

@Module({
  controllers: [HealthController],
  imports:[
    // Make sure TypeOrmModule is available in the module context
    TypeOrmModule.forRoot({ ... }),
    TerminusModule
  ],
})
export class HealthModule { }

  • Setup your HealthController which executes your Health Check.
// health.controller.ts

@Controller('health')
export class HealthController {
  constructor(
    private health: HealthCheckService,
    private db: TypeOrmHealthIndicator,
  ) {}

  @Get()
  @HealthCheck()
  readiness() {
    return this.health.check([
      async () => this.db.pingCheck('database', { timeout: 300 }),
    ]);
  }
}

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

{
  "status": "ok",
  "info": {
    "database": {
      "status": "up"
    }
  },
  "details": {
    "database": {
      "status": "up"
    }
  }
}

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:

  • Fork & Clone the repository
  • Install the dependencies
pnpm i
pnpm dev

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

cd sample/000-dogs-app
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:

pnpm test

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

docker compose up -d
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.