@unifig/adapter-env
v1.1.3
Published
Environmental variables adapter for unifig
Downloads
13,061
Readme
Env variables & files adapter for Unifig
Table of Contents
Installation
npm i @unifig/adapter-env
# or
yarn add @unifig/adapter-env
Quick Start
# .env
PORT=3000
export class DbSettings {
@From('DB_URL')
@IsString()
url: string;
@From('DB_PASSWORD')
@IsString()
password: string;
}
export class AppSettings {
@From('PORT')
@IsInt()
port: number;
@Nested(() => DbSettings)
@IsDefined()
db: DbSettings;
}
import { Config } from '@unifig/core';
import { EnvConfigAdapter } from '@unifig/adapter-env';
function bootstrap() {
Config.registerSync({
template: Settings,
adapter: new EnvConfigAdapter(),
});
const { port } = Config.getValues(AppSettings);
console.log(port); // output: 3000
}
bootstrap();
Options
| Property | What it does | Required |
| ----------------- | --------------------------------------------------------------------------------------------------------------------- | -------- |
| envFilesPaths
| Path to optional environment files to be loaded in given order. Values from them will be overwritten by process envs. | × |
| ignoreEnvVars
| If "true", environment variables will not be loaded. | × |
| expandVariables
| See https://www.npmjs.com/package/dotenv-expand. | × |
License
This project is licensed under the MIT License - see the LICENSE file for details.