Socket
Book a DemoInstallSign in
Socket

@nestcfork/boot

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestcfork/boot

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

0.7.5
beta
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

NestCloud - Boot

NPM Version Package License NPM Downloads Travis Linux Coverage

Description

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

Installation

$ npm i --save @nestcfork/boot

Quick Start

Import Module

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

  • Inject Boot instance:
import { Injectable, OnModuleInit } from '@nestjs/common';
import { InjectBoot, Boot } from '@nestcfork/boot';

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

  onModuleInit() {
      const port = this.boot.get<number>('service.port', 3000);
  }
}
  • Inject value:
import { Injectable } from '@nestjs/common';
import { BootValue } from '@nestcfork/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.

FAQs

Package last updated on 21 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.