# nestjs-health

> Create a NestJS health check library

Latest version **0.0.2** (published 2022-10-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install nestjs-health
pnpm add nestjs-health
yarn add nestjs-health
bun add nestjs-health
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2022-10-22 |
| First published | 2022-10-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 16 |
| Dependencies | 3 |
| Unpacked size | 33.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Connie Leung |
| Maintainers | railsstudent |
| Keywords | nestjs, terminus, redis, bull, typeorm, microservices, application |

## Links

- npm: https://www.npmjs.com/package/nestjs-health
- Repository: https://github.com/railsstudent/nestjs-health
- Homepage: https://github.com/railsstudent/nestjs-health#readme
- Issues: https://github.com/railsstudent/nestjs-health/issues
- npm.io page: https://npm.io/package/nestjs-health

## Dependencies (3)

- [rxjs](https://npm.io/package/rxjs.md) ^7.2.0
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2022-10-22
- 0.0.1 — 2022-10-22

## README

<p align="center">
  <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>
## Description

NestJS health check library.

## What does it do?

- Check backend application is running
- Optionally use TypeOrmHealthIndicator to ping default database that uses TypeORM
- Optionally check that redis is set up
- Optionally checl that bull queue is connect to redis and ready to accept jobs
- Provide custom indicator functions to execute
- Define /health endpoint to carry health check and output response

## Installation

```bash
$ npm install nestjs-health
```

## Register synchronously

```typescript
import { HealthModule } from 'nestjs-health';

@Module({
  HealthModule.forRoot({
    app: 'nestjs-health-terminus',
    backendUrl: 'http://localhost:3000',
    shouldCheckDatabase: true,
    queueNames: ['fibonacci', 'prime'],
    redisOptions: {
      host: 'localhost',
      port: 6379,
    },
  })
})
export class AppModule {}
```

## Register asynchronously

```typescript
import { HealthModule } from 'nestjs-health';

@Module({
  HealthModule.forRootAsync({
    inject: [ConfigService, HttpHealthIndicator],
    useFactory: (configService: ConfigService, http:  HttpHealthIndicator) => {
      return {
        app: 'nestjs-health-terminus',
        backendUrl: configService.get<string>('BACKEND_DOMAIN', ''),
        shouldCheckDatabase: true,
        queueNames: ['fibonacci', 'prime'],
        redisOptions: {
          host: configService.get<string>('REDIS_HOST', 'localhost'),
          port: configService.get<number>('REDIS_PORT', 0),
        },
        indicatorFunctions: [
          () => http.pingCheck('nestjs-docs', 'https://docs.nestjs.com'),
          () => http.pingCheck('angular-docs', 'https://angular.io/docs'),
        ],
      };
    },
  });
})
export class AppModule {}
```

## Route to /heath endpoint

```json
// http://localhost:3000/health

{
  "status": "ok",
  "info": {
    "nestjs-health-terminus": {
      "status": "up"
    },
    "database": {
      "status": "up"
    },
    "redis": {
      "status": "up"
    },
    "bull": {
      "status": "up"
    },
    "nestjs-docs": {
      "status": "up"
    },
    "angular-docs": {
      "status": "up"
    }
  },
  "error": {},
  "details": {
    "nestjs-health-terminus": {
      "status": "up"
    },
    "database": {
      "status": "up"
    },
    "redis": {
      "status": "up"
    },
    "bull": {
      "status": "up"
    },
    "nestjs-docs": {
      "status": "up"
    },
    "angular-docs": {
      "status": "up"
    }
  }
}
```

---
_Source: https://npm.io/package/nestjs-health · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
