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

    1.0.0 • Public • Published

    Nest Config

    GitHub tag
    A config component for nestJS.

    Install

    yarn add @bashleigh/nest-config
    npx add --save @bashleigh/nest-config

    create a .env file and insert your configurations

    touch .env && echo 'APP_TEST=true' >> .env

    How to use

    Get

    Get a parameter from the config

    const test = this.config.get('APP_TEST');

    With a default option

    const test = this.config.get('APP_TEST', false);

    Has

    Check your config has a parameter defined

    this.config.has('APP_TEST');

    Root

    Get a root path like /var/www/mypath

    this.config.root('mypath'); //returns /var/www/mypath
    this.config.root('file.txt'); //returns /var/www/file.txt

    Src

    Get a path within src (uses root)

    this.config.src('mypath'); //returns /var/www/src/mypath

    Integrating with modules

    import {
        Injectable,
    } from '@nestjs/common';
     
    import ConfigModule from '@bashleigh/nest-config';
     
    @Injectable({
      imports: [
          ConfigModule,
      ],
      controllers: [],
      providers: [],
    })
    export class ApplicationModule {
      constructor() {}
    }
     

    Injection

    Inject the component into a controller

     
    import {
        Controller,
    } from '@nestjs/common';
     
    import {
        ConfigService,
    } from '@bashleigh/nest-config';
     
    @Controller('user')
    export default class UserController {
        constructor(private readonly config: ConfigService) {}
        
    }
     

    Injection with decorator

    import {
        Controller,
    } from '@nestjs/common';
    import {
        InjectConfig,
    } from '@bashleigh/nest-config';
     
    @Controller('user')
    export default class UserController {
        constructor(@InjectConfig() private readonly config) {}
    }

    Built by AS

    Install

    npm i @bashleigh/nest-config

    DownloadsWeekly Downloads

    66

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    27.3 kB

    Total Files

    23

    Last publish

    Collaborators

    • bashleigh