@class-config/source-env
v0.6.0
Published
The package of get config from environment
Downloads
2
Readme
@class-config/source-env
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>();