@ddboot/config
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

@ddboot/logger

Nest Logo

Description

config module for Nest

Installation

$ npm i --save @ddboot/config yaml lodash

Quick Start

  • import ConfigModule in your root module
import { Module } from '@nestjs/common';
import { ConfigModule } from '@ddboot/config';
@Module({
  imports: [
    ConfigModule.forRootAsync({
      filePath: '',
      fileName: 'config.yaml',
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
  • use LoggerService in your service
import { Injectable } from '@nestjs/common';
import { InjectConfig, ConfigService } from '@ddboot/config';

@Injectable()
export class AppService {
  //must use @InjectConfig() to inject logger
  constructor(@InjectConfig() private readonly config: ConfigService) {}
  getHello(): string {
    this.config.get('client.id');
    return 'Hello World!';
  }
}
  • or use @Value() decorator in your service
import { Injectable } from '@nestjs/common';
import { Value } from '@ddboot/config';

@Injectable()
export class AppService {
  @Value('client.id')
  private clientId: string;

  getHello(): string {
    this.logger.info('getHello');
    return 'Hello World!';
  }
}

Note: @Value() decorator will inject Logger instance to your service, so you can use this.logger to log. If you want to use @InjectLogger() decorator, you must use this.iLogger.getLogger() to get Logger instance.

Configuration

  • Config
interface Config {
  path?: string;
  level?: string;
  // file name
  name?: string;
  // console show log
  console?: boolean;
}

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

License

@nsboot/logger is MIT licensed.

Readme

Keywords

Package Sidebar

Install

npm i @ddboot/config

Weekly Downloads

0

Version

1.2.1

License

MIT

Unpacked Size

17.4 kB

Total Files

18

Last publish

Collaborators

  • charlesmaxwellyoung