Socket
Socket
Sign inDemoInstall

@unifig/env

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unifig/env

Environmental variables adapter for unifig


Version published
Maintainers
1
Created
Source

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.

Keywords

FAQs

Package last updated on 02 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc