0.7.13-node1011 • Published 5 years ago

@nestcloud/boot v0.7.13-node1011

Weekly downloads
482
License
MIT
Repository
github
Last release
5 years ago

NestCloud - Boot

Description

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

Installation

$ npm i --save @nestcloud/boot

Quick Start

Import Module

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.

web:
  name: example-service
  port: 3000

Usage

There are two ways to get your config data,

  1. Inject Boot instance:
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);
  }
}
  1. Inject value:
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.

template:

process.env.SERVICE_ID = 'your-service-id';
process.env.SERVICE_NAME = 'your-service-name';
service:
  id: ${{ SERVICE_ID }}
  name: ${{ SERVICE_NAME }}
  port: 3000
  address: http://${{ service.name }}:${{ service.port }}

result:

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.

fieldtypedescription
options.filePathstringthe config file path

class Boot

get<T>(path?: string, defaults?: T): T

Get configurations

fieldtypedescription
pathstringpath of configurations
defaultsanydefault 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

License

NestCloud is MIT licensed.

0.7.3-node1011

5 years ago

0.7.13-node1011

5 years ago

0.7.17

6 years ago

0.6.13

6 years ago

0.7.16

6 years ago

0.6.12

6 years ago

0.7.15

6 years ago

0.7.14

6 years ago

0.7.13

6 years ago

0.7.11

6 years ago

0.7.12

6 years ago

0.7.10

6 years ago

0.7.9-2

6 years ago

0.7.9-1

6 years ago

0.7.9-0

6 years ago

0.7.9

6 years ago

0.7.8

6 years ago

0.7.6

6 years ago

0.7.5

6 years ago

0.7.3

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.11

6 years ago

0.6.10-22

6 years ago

0.6.10

6 years ago

0.6.10-18

6 years ago

0.6.10-20

6 years ago

0.6.10-21

6 years ago

0.6.10-19

6 years ago

0.6.10-16

6 years ago

0.6.10-17

6 years ago

0.6.10-15

6 years ago

0.6.10-12

6 years ago

0.6.10-13

6 years ago

0.6.10-14

6 years ago

0.6.10-6

6 years ago

0.6.10-7

6 years ago

0.6.10-11

6 years ago

0.6.10-10

6 years ago

0.6.10-8

6 years ago

0.6.10-9

6 years ago

0.6.10-4

6 years ago

0.6.10-5

6 years ago

0.6.10-3

6 years ago

0.6.10-2

6 years ago

0.6.9

6 years ago

0.6.8

6 years ago

0.6.7

7 years ago

0.6.6

7 years ago

0.6.3

7 years ago

0.6.5

7 years ago

0.6.4

7 years ago

0.6.2

7 years ago

0.6.0

7 years ago

0.6.0-y.4

7 years ago

0.6.0-y.3

7 years ago

0.6.0-y.2

7 years ago

0.6.0-y.1

7 years ago

0.6.0-y.0

7 years ago

0.6.0-4

7 years ago

0.6.0-3

7 years ago

0.6.0-2

7 years ago

0.6.0-1

7 years ago

0.6.0-0

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0-9

7 years ago

0.5.0-8

7 years ago

0.5.0-7

7 years ago

0.5.0-6

7 years ago

0.5.0-5

7 years ago

0.5.0-4

7 years ago

0.5.0-3

7 years ago

0.5.0-2

7 years ago

0.5.0-1

7 years ago

0.5.0-0

7 years ago

0.4.5-3

7 years ago

0.4.5-2

7 years ago

0.4.5-1

7 years ago

0.4.5-0

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.17

7 years ago

0.3.16

7 years ago

0.3.16-0

7 years ago

0.3.15

7 years ago

0.3.14

7 years ago

0.3.14-2

7 years ago

0.3.14-1

7 years ago

0.3.14-0

7 years ago

0.3.13

7 years ago

0.3.12

7 years ago

0.3.10

7 years ago

0.3.9

7 years ago

0.3.9-0

7 years ago

0.3.8

7 years ago

0.3.8-5

7 years ago

0.3.8-4

7 years ago

0.3.8-3

7 years ago

0.3.8-2

7 years ago

0.3.8-1

7 years ago

0.3.8-0

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.5-3

7 years ago

0.2.5-2

7 years ago

0.2.5-1

7 years ago

0.2.5-0

7 years ago

0.2.4

7 years ago

0.2.4-3

7 years ago

0.2.4-2

7 years ago

0.2.4-1

7 years ago

0.2.4-0

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.1-5

7 years ago

0.2.1-4

7 years ago

0.2.1-3

7 years ago

0.2.1-2

7 years ago

0.2.1-1

7 years ago

0.2.1-0

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago