Skip to content

A library to load .env files and interact with the environment

License

Notifications You must be signed in to change notification settings

media-service-dev/environment

Repository files navigation

@mscs/environment

A library to load and interact with the environment.

Installation

$ yarn add @mscs/environment

Usage

Short example:

import { EnvironmentLoader, ProcessEnvironment } from "@mscs/environment";

async function runtime(){
    const environment = new ProcessEnvironment();
    const environmentLoader = new EnvironmentLoader(environment);

    await environmentLoader.loadEnvironment(__dirname + '/../.env');

    if(environment.has('FOO')){
        const foo = environment.get("FOO");
        // ...
    }
}

runtime()
    .catch(console.error);

This example expect that you are in a root file of the src directory in your project.

Documentation

Currently, you have to build the documentation on your own.

$ git clone git@github.com:media-service-dev/environment.git
$ cd environment
$ yarn
$ yarn run docs

Important note

The parser for .env-files and the environment file loading order logic was ported from Symfony.

Since Symfony is, for good reason, a registered trademark, please take note that we are in no way associated with the Symfony brand or the SensioLabs organization. Therefore, we don't represent or speak for any of them.