Env variables & files adapter for Unifig
Table of contents
Installation
npm i @unifig/env
yarn add @unifig/env
Quick Start
PORT=3000
export class Settings {
@From('PORT')
@IsInt()
port: number;
}
import { Config } from '@unifig/core';
import { EnvConfigAdapter } from '@unifig/env';
async function bootstrap() {
await Config.register({
template: Settings,
adapter: new EnvConfigAdapter(),
});
console.log(Config.get(Settings).port);
}
bootstrap();
Properties Mapping
Environment variables are mapped to 1D dictionary.
PORT=3000
DB_HOST=localhost
DB_PORT=4588
{
PORT: 3000,
DB_HOST: 'localhost',
DB_PORT: 4588
}
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.