/EnvDotNet

Primary LanguageC#MIT LicenseMIT

EnvDotNet

Build Unit Tests codecov DeepSource

Env.Net is a simple library to read environment variables from config files.

Usage

First, structure your env file like so:

key1=value1
key2=value2

Then, you can read the environment variables like so:

using EnvDotNet;

Env.Init(); // Env.Init() loads the env file and makes it available globally. The method defaults to using .env as the file name, but can take a string parameter to specify the file name.
string key1 = Env.Get("key1");

Env.Net has numerous other features, such as:

Using multiple env files

Env file1 = new Env("file1.env");
Env file2 = new Env("file2.env");

string key1 = file1["key1"];
string key2 = file2["key2"];

Using default values

Env.Init();
string key = Env.Get("key", "default");

Contains Key

Env.Init();
Env local = new Env("local.env");
bool containsKey = Env.ContainsKey("key");
bool containsLocalKey = local.Contains("key");