Description

Module for configuring the application using files, extends Config base class.

Features:

  • default configuration in config.json file
  • configuration depending on the NODE_ENV environment variable in config.{NODE_ENV}.json file
  • package.json data access in "package" namespace

How to use:

In cwd of you app, near package.json, create 2 files:

# config.json
{
"app": "test"
}

# config.debug.json:
{
"title": "My awesome app"
}

Example

import { Core, injectable, inject, container, Types } from '@biorate/inversion';
import { IConfig } from '@biorate/config';
import { FileConfig } from '@biorate/file-config';

@injectable()
class Root extends Core() {
@inject(Types.Config) public config: IConfig;
}

container.bind<IConfig>(Types.Config)
.to(FileConfig)
.inSingletonScope();

container.bind<Root>(Root).toSelf().inSingletonScope();

(async () => {
const root = await container.get(Root).$run();

console.log(root.config.get('package'));
// {
// "name": "file-config-test",
// "version": "0.0.0",
// "description": "Test package.json",
// "keywords": [],
// "author": "llevkin",
// "license": "MIT"
// }

console.log(root.config.get('app')); // test
console.log(root.config.get('title')); // My awesome app
})();

Hierarchy

  • Config
    • FileConfig

Constructors

Properties

data: {}

Type declaration

    Template: {
        empty: boolean;
        function: boolean;
        link: boolean;
        regexp: boolean;
        string: boolean;
    }

    Type declaration

    • empty: boolean
    • function: boolean
    • link: boolean
    • regexp: boolean
    • string: boolean
    _root: string = ...

    Methods

    • Type Parameters

      • T = unknown

      Parameters

      • path: PropertyPath
      • Optional def: T

      Returns T

    • Parameters

      • path: PropertyPath

      Returns boolean

    • Parameters

      • data: unknown

      Returns void

    • Parameters

      • path: PropertyPath
      • value: unknown

      Returns void

    • Type Parameters

      • T = unknown

      Parameters

      • value: string
      • Optional def: T

      Returns unknown

    • Type Parameters

      • T = unknown

      Parameters

      • object: unknown
      • Optional def: T

      Returns any

    • Parameters

      • path: string

      Returns typeof FileConfig

      Description

      Change application root. Application root is equal process.cwd() by default

      Example

      FileConfig.root('/www/my-app/');
      

      Example

      container.bind<IConfig>(Types.Config)
      .to(FileConfig.root('/www/my-app/'))
      .inSingletonScope();