0.7.17 • Published 3 years ago

@nestcloud/boot v0.7.17

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

Description

A component of nestcloud. NestCloud is a nest framework micro-service solution.

中文文档

A Nest module to get configurations when the app bootstrap.

Installation

$ npm i --save @nestcloud/boot

Quick Start

Import Module

import { Module } from '@nestjs/common';
import { BootModule } from '@nestcloud/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.

web:
  name: example-service
  port: 3000

Usage

There are two ways to get configurations,

  1. Inject Boot instance:
import { Injectable } from '@nestjs/common';
import { InjectBoot, Boot } from '@nestcloud/boot';

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

  getPort() {
      return this.boot.get('web.port', 3000);
  }
}
  1. Inject value:
import { Injectable } from '@nestjs/common';
import { Bootstrap, BootValue } from '@nestcloud/boot';

@Injectable()
@Bootstrap()
export class TestService {
  @BootValue('web.port', 3000)
  private readonly port: number;

  getPort() {
      return this.port;
  }
}

Get configurations with env.

The boot module supports get configurations with env, use ${} expression, example:

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.

fieldtypedescription
pathstringthe config file path
filenamestringthe config filename

class Boot

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

Get configurations

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

Bootstrap(): ClassDecorator

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

Inject configuration to class attribute.

Stay in touch

License

NestCloud is MIT licensed.

0.7.3-node1011

3 years ago

0.7.13-node1011

3 years ago

0.7.17

4 years ago

0.6.13

4 years ago

0.7.16

4 years ago

0.6.12

4 years ago

0.7.15

4 years ago

0.7.14

4 years ago

0.7.13

4 years ago

0.7.11

4 years ago

0.7.12

4 years ago

0.7.10

4 years ago

0.7.9-2

4 years ago

0.7.9-1

4 years ago

0.7.9-0

4 years ago

0.7.9

4 years ago

0.7.8

4 years ago

0.7.6

4 years ago

0.7.5

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.11

4 years ago

0.6.10-22

4 years ago

0.6.10

4 years ago

0.6.10-18

4 years ago

0.6.10-20

4 years ago

0.6.10-21

4 years ago

0.6.10-19

4 years ago

0.6.10-16

4 years ago

0.6.10-17

4 years ago

0.6.10-15

4 years ago

0.6.10-12

4 years ago

0.6.10-13

4 years ago

0.6.10-14

4 years ago

0.6.10-6

4 years ago

0.6.10-7

4 years ago

0.6.10-11

4 years ago

0.6.10-10

4 years ago

0.6.10-8

4 years ago

0.6.10-9

4 years ago

0.6.10-4

4 years ago

0.6.10-5

4 years ago

0.6.10-3

4 years ago

0.6.10-2

4 years ago

0.6.9

4 years ago

0.6.8

4 years ago

0.6.7

4 years ago

0.6.6

4 years ago

0.6.3

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.2

4 years ago

0.6.0

4 years ago

0.6.0-y.4

4 years ago

0.6.0-y.3

4 years ago

0.6.0-y.2

4 years ago

0.6.0-y.1

4 years ago

0.6.0-y.0

4 years ago

0.6.0-4

4 years ago

0.6.0-3

4 years ago

0.6.0-2

4 years ago

0.6.0-1

4 years ago

0.6.0-0

4 years ago

0.5.3

4 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0-9

5 years ago

0.5.0-8

5 years ago

0.5.0-7

5 years ago

0.5.0-6

5 years ago

0.5.0-5

5 years ago

0.5.0-4

5 years ago

0.5.0-3

5 years ago

0.5.0-2

5 years ago

0.5.0-1

5 years ago

0.5.0-0

5 years ago

0.4.5-3

5 years ago

0.4.5-2

5 years ago

0.4.5-1

5 years ago

0.4.5-0

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.17

5 years ago

0.3.16

5 years ago

0.3.16-0

5 years ago

0.3.15

5 years ago

0.3.14

5 years ago

0.3.14-2

5 years ago

0.3.14-1

5 years ago

0.3.14-0

5 years ago

0.3.13

5 years ago

0.3.12

5 years ago

0.3.10

5 years ago

0.3.9

5 years ago

0.3.9-0

5 years ago

0.3.8

5 years ago

0.3.8-5

5 years ago

0.3.8-4

5 years ago

0.3.8-3

5 years ago

0.3.8-2

5 years ago

0.3.8-1

5 years ago

0.3.8-0

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.5-3

5 years ago

0.2.5-2

5 years ago

0.2.5-1

5 years ago

0.2.5-0

5 years ago

0.2.4

5 years ago

0.2.4-3

5 years ago

0.2.4-2

5 years ago

0.2.4-1

5 years ago

0.2.4-0

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.1-5

5 years ago

0.2.1-4

5 years ago

0.2.1-3

5 years ago

0.2.1-2

5 years ago

0.2.1-1

5 years ago

0.2.1-0

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago