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

0.0.7 • Public • Published

Nest-kr/config

This library load and validate environment variables

Installation

$ npm install --save @nest-kr/config

How to use

Set config file with @Config(key). you have to pass key for finding your config from ConfigService.

import { Transform } from 'class-transformer';
import { IsNumber } from 'class-validator';

import { Config } from '../src/Config';

@Config('app')
export class AppConfig {
    @IsNumber()
    public port: number = parseInt(process.env.PORT, 10);

    @IsString()
    public serviceId: string = process.env.SERVICE_ID;
}

Register your config files to ConfigModule

import {ConfigModule} from '@nest-kr/config';

@Module({
    imports: [ConfigModule.forRoot(AppConfig, ...)],
})
export class AppModule {}

Get your config from ConfigService using key

// in bootstrap
import {ConfigService} from '@nest-kr/config';

async function bootstrap(){
    const app = await NestFactory.create(AppModule);
    const configService: ConfigService = app.get(ConfigService);

    const appConfig:AppConfig = configService.get('app');
    ...
}

// in class
@Injectable()
class TestService{

    constructor(private configService: ConfigService){}

    async function test(){
        const appConfig: AppConfig = this.configService.get('app');
    }
}

Readme

Keywords

Package Sidebar

Install

npm i @nest-kr/config

Weekly Downloads

0

Version

0.0.7

License

MIT

Unpacked Size

11.3 kB

Total Files

16

Last publish

Collaborators

  • loveloper