0.7.0 • Published 2 years ago

@unifig/env v0.7.0

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

Env variables & files adapter for Unifig

Table of contents

Installation

npm i @unifig/env
# or
yarn add @unifig/env

Quick Start

# .env
PORT=3000
export class DbSettings {
  @From('DB_URL')
  @IsString()
  url: string;

  @From('DB_PASSWORD')
  @IsString()
  password: string;
}

export class Settings {
  @From('PORT')
  @IsInt()
  port: number;

  @Nested(() => DbSettings)
  @IsDefined()
  db: DbSettings;
}
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); // output: 3000
}

bootstrap();

Properties Mapping

Environment variables are mapped to 1D dictionary.

# .env
PORT=3000
DB_HOST=localhost
DB_PORT=4588
// adapter output
{
  PORT: 3000,
  DB_HOST: 'localhost',
  DB_PORT: 4588
}

Options

PropertyWhat it doesRequired
envFilesPathsPath to optional environment files to be loaded in given order. Values from them will be overwritten by process envs.×
ignoreEnvVarsIf "true", environment variables will not be loaded.×
expandVariablesSee https://www.npmjs.com/package/dotenv-expand.×

License

This project is licensed under the MIT License - see the LICENSE file for details.

0.7.0

2 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.2

3 years ago

0.2.0

3 years ago