# @nestcloud/boot

> NestCloud is a Node.js micro-service solution, writing by Typescript language and Nest.js.

Latest version **0.7.17** (published 2020-10-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @nestcloud/boot
pnpm add @nestcloud/boot
yarn add @nestcloud/boot
bun add @nestcloud/boot
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.17 |
| Published | 2020-10-29 |
| First published | 2019-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 25.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 419 |
| Author | Miaowing |
| Maintainers | zfeng |

## Links

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

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [yamljs](https://npm.io/package/yamljs.md) ^0.3.0
- [handlebars](https://npm.io/package/handlebars.md) ^4.1.1
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.12

## Recent versions

- 0.7.17 (latest) — 2020-10-29
- 0.7.3-node1011 (test) — 2021-06-03
- 0.7.3 (beta) — 2020-03-05
- 0.7.1 (next) — 2020-01-19
- 0.7.13-node1011 — 2021-06-03
- 0.6.13 — 2020-09-17
- 0.7.16 — 2020-09-15
- 0.6.12 — 2020-09-15
- 0.7.15 — 2020-08-12
- 0.7.14 — 2020-08-12
- 0.7.13 — 2020-07-27
- 0.7.12 — 2020-07-24
- 0.7.11 — 2020-07-24
- 0.7.10 — 2020-07-23
- 0.7.9 — 2020-07-23
- … 123 more at https://npm.io/package/@nestcloud/boot/versions

## README

[travis-image]: https://api.travis-ci.org/nest-cloud/nestcloud.svg?branch=master
[travis-url]: https://travis-ci.org/nest-cloud/nestcloud
[linux-image]: https://img.shields.io/travis/nest-cloud/nestcloud/master.svg?label=linux
[linux-url]: https://travis-ci.org/nest-cloud/nestcloud

# NestCloud - Boot

<p align="center">
    <a href="https://www.npmjs.com/~nestcloud" target="_blank"><img src="https://img.shields.io/npm/v/@nestcloud/core.svg" alt="NPM Version"/></a>
    <a href="https://www.npmjs.com/~nestcloud" target="_blank"><img src="https://img.shields.io/npm/l/@nestcloud/core.svg" alt="Package License"/></a>
    <a href="https://www.npmjs.com/~nestcloud" target="_blank"><img src="https://img.shields.io/npm/dm/@nestcloud/core.svg" alt="NPM Downloads"/></a>
    <a href="https://travis-ci.org/nest-cloud/nestcloud" target="_blank"><img src="https://travis-ci.org/nest-cloud/nestcloud.svg?branch=master" alt="Travis"/></a>
    <a href="https://travis-ci.org/nest-cloud/nestcloud" target="_blank"><img src="https://img.shields.io/travis/nest-cloud/nestcloud/master.svg?label=linux" alt="Linux"/></a>
    <a href="https://coveralls.io/github/nest-cloud/nestcloud?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nest-cloud/nestcloud/badge.svg?branch=master" alt="Coverage"/></a>
</p>

## Description

NestCloud component for getting local configurations and environment values when the app bootstrap.

## Installation

```bash
$ npm i --save @nestcloud/boot
```

## Quick Start

### Import Module

```typescript
import { Module } from '@nestjs/common';
import { BootModule } from '@nestcloud/boot';
import * as path from 'path';

@Module({
  imports: [
    BootModule.forRoot({ 
      filePath: path.resolve(__dirname, 'config.yaml'),
    }),
  ],
})
export class AppModule {}
```

### Configurations

Boot module will load `config.yaml`, `config.${env}.yaml` two files.

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

## Usage

There are two ways to get your config data,
 
 1. Inject Boot instance:

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

@Injectable()
export class ConfigService implements OnModuleInit {
  constructor(
    @InjectBoot() private readonly boot: Boot
  ) {}

  onModuleInit() {
      const port = this.boot.get<number>('service.port', 3000);
  }
}
```

2. Inject value:

```typescript
import { Injectable } from '@nestjs/common';
import { BootValue } from '@nestcloud/boot';

@Injectable()
export class ConfigService {
  @BootValue('service.port', 3000)
  private readonly port: number;
}
```

## Template Compile.

Dependency [handlebars.js](https://github.com/wycats/handlebars.js).

template:

```typescript
process.env.SERVICE_ID = 'your-service-id';
process.env.SERVICE_NAME = 'your-service-name';
```

```yaml
service:
  id: ${{ SERVICE_ID }}
  name: ${{ SERVICE_NAME }}
  port: 3000
  address: http://${{ service.name }}:${{ service.port }}
```

result:

```yaml
service:
  id: your-service-id
  name: your-service-name
  port: 3000
  address: http://your-service-name:3000
```

## API

### class BootModule

#### static forRoot\(options: BootOptions\): DynamicModule

Register boot module.

| field            | type    | description              |
| :--------------- | :------ | :----------------------- |
| options.filePath | string  | the config file path     |

### 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 |

## Decorators

### InjectBoot\(\): PropertyDecorator

Inject Boot instance.

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

Inject 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/@nestcloud/boot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
