Description

File-based config loader

Features

  • File config loader middleware
  • Basic configuration in config.json
  • Env-based configuration in config.{NODE_ENV}.json

Example

./config.json

{
"hello": "world"
}

Example

./index.ts

import { inject, container, Types, Core } from '@biorate/inversion';
import { IConfig, Config } from '@biorate/config';
import { ConfigLoader } from '@biorate/config-loader';
import { ConfigLoaderFs } from '@biorate/config-loader-fs';

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

container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
container.bind<ConfigLoader>(Types.ConfigLoaderFs).to(ConfigLoaderFs).inSingletonScope();
container.bind<Root>(Root).toSelf().inSingletonScope();

(async () => {
const root = container.get<Root>(Root);
await root.$run();
root.config.get('hello'); // world
})();

See

@biorate/config-loader docs for details

Hierarchy

Constructors

Properties

Methods

Constructors

Properties

config: IConfig

Description

Config dependency

directory: string = ...

Description

Root path

Methods

  • Parameters

    • file: string
    • directory: string = ConfigLoaderFs.directory
    • Optional namespace: string
      Optional

    Returns Promise<void>

    Description

    Load file

  • Parameters

    • path: string

    Returns typeof ConfigLoaderFs

    Description

    Change application root method. 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();

Generated using TypeDoc