0.6.0 • Published 2 years ago

@class-config/source-env v0.6.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

@class-config/source-env

Node.js CI codecov

This is the class config source. This package provides the ability to get configuration from environment variables.

Usage

Example

import 'reflect-metadata';
import { BaseConfig, Config, ConfigField, From } from '@class-config/core';
import { Env } from '@class-config/source-env';

process.env.SERVER_HOST = 'localhost';
process.env.SERVER_PORT = '8080';

@Config()
class Configuration extends BaseConfig {
  /**
   * The server host
   */
  @ConfigField()
  @From(new Env('SERVER_HOST'))
  public host!: string;

  /**
   * The server port
   */
  @ConfigField()
  @From(new Env('SERVER_PORT'))
  public port!: number;
}

// configuration = { "host": "localhost", "port": 8080 }
const configuration = await Configuration.init<Configuration>();