# nest-boot

> A Nest framework (node.js) module for getting config parameters when the app is running.

Latest version **3.0.1** (published 2019-03-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install nest-boot
pnpm add nest-boot
yarn add nest-boot
bun add nest-boot
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2019-03-01 |
| First published | 2018-05-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 54.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Miaowing |
| Maintainers | zfeng |

## Links

- npm: https://www.npmjs.com/package/nest-boot
- Repository: https://github.com/nest-cloud/nest-boot
- Homepage: https://github.com/nest-cloud/nest-boot#readme
- Issues: https://github.com/nest-cloud/nest-boot/issues
- npm.io page: https://npm.io/package/nest-boot

## Dependencies (4)

- [yamljs](https://npm.io/package/yamljs.md) ^0.3.0
- [nest-common](https://npm.io/package/nest-common.md) 0.0.1
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.108
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.12

## Recent versions

- 3.0.1 (latest) — 2019-03-01
- 3.0.0 — 2019-02-14
- 0.0.1 — 2019-02-14
- 2.3.0 — 2018-11-24
- 2.2.0 — 2018-11-24
- 2.1.0 — 2018-11-23
- 2.0.0 — 2018-09-12
- 1.1.0 — 2018-09-10
- 1.0.0 — 2018-09-10
- 0.2.0 — 2018-09-06
- 0.1.1 — 2018-05-16
- 0.1.0 — 2018-05-16

## README

<p align="center">
  <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
</p>

## Description

A component of [nestcloud](http://github.com/nest-cloud/nestcloud). NestCloud is a nest framework micro-service solution.
  
[中文文档](https://nestcloud.org/solutions/ben-di-pei-zhi)

A [Nest](https://github.com/nestjs/nest) module to get configurations when the app bootstrap.

## Installation

```bash
$ npm i --save nest-boot
```

## Quick Start

#### Import Module

```typescript
import { Module } from '@nestjs/common';
import { BootModule } from 'nest-boot';

const env = process.env.NODE_ENV;

@Module({
  imports: [BootModule.register(__dirname, `bootstrap-${env}.yml`)],
})
export class ApplicationModule {}
```

#### Yaml Config File

eg: bootstrap-development.yml.

```yaml
web:
  name: example-service
  port: 3000
```

#### Usage

There are two ways to get configurations, the first, use get method:

```typescript
import { Injectable } from '@nestjs/common';
import { InjectBoot, Boot } from 'nest-boot';

@Injectable()
export class TestService {
  constructor(@InjectBoot() private readonly boot: Boot) {}

  getPort() {
      return this.boot.get('web.port', 3000);
  }
}
```

The second, use @BootValue:

```typescript
import { Injectable } from '@nestjs/common';
import { InjectBoot, Boot, DynamicBoot, BootValue } from 'nest-boot';

@Injectable()
export class TestService extends DynamicBoot {
  @BootValue('web.port', 3000)
  private readonly port: number; 
  
  constructor(
      @InjectBoot() private readonly boot: Boot
  ) {
      super(boot);
  }

  getPort() {
      return this.port;
  }
}
```

#### Get configurations with env.

nest-boot supports get configurations with env, use ${} expression, example:

```yaml
web:
  serviceId: ${ SERVICE_ID || example-service }
  serviceName: ${ SERVICE_NAME || example-service }
  port: 3000
```

## API

### class BootModule

#### static register\(path: string, filename: string\): DynamicModule

Import nest boot module.

| field | type | description |
| :--- | :--- | :--- |
| path | string | the config file path |
| filename | string | the config filename |

### class Boot

#### get&lt;T&gt;\(path: string, defaults?: T\): T

Get configurations

| field | type | description |
| :--- | :--- | :--- |
| path |  string | path of configurations |
| defaults | any | default value if the specific configuration is not exist |

#### getEnv\(\): string

Get current NODE\_ENV value, if not set, it will return 'development'.

#### getFilename\(\): string

Get the current config filename.

#### getConfigPath\(\): string

Get the current path of the config file.

#### getFullConfigPath\(\): string

Get the current full path of the config file.

### Decorator

#### InjectBoot\(\): PropertyDecorator

Inject Boot instance.

#### BootValue\(path: string, defaultValue?: any\): PropertyDecorator

Set configuration to class attribute.

## Stay in touch

- Author - [NestCloud](https://github.com/nest-cloud)

## License

  NestCloud is [MIT licensed](LICENSE).

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