dotenv


https://github.com/benmerckx/dotenv/

To install, run:

haxelib install dotenv 0.0.0 

See using Haxelib in Haxelib documentation for more information.

README.md

dotenv

Build Status

Loads environment variables into class' statics. Variables will be loaded from a '.env' file, if one exists. Any existing environment variables will not be overwritten (unless specified by the overload option).

class DatabaseConfig {
	public static var DB_NAME: String;
	public static var DB_USER: String;
	public static var DB_PASS: String;
	public static var DB_HOST: String;
	public static var DB_PORT: Int;
	
	static function __init__() dotenv.Env.init();
}

Can be initialized from the following '.env' file:

# Comments are allowed
DB_NAME=name
DB_USER=user
DB_PASS=pass
DB_HOST=host
DB_PORT=3306

Dotenv does not actually set these values as environment variables as some targets (java, lua) do not support this.

Types

A variable can be typed as String, Int, Float or Bool (you can use true and false).

Optional

Optional values can be denoted using Null<T>. Non-optional values will throw if not found in the environment.

public static var DB_PORT: Null<Int>;

Defaults

Default values can be set using metadata:

@:default(3306)
public static var DB_PORT: Int;

Multiline

Multiline strings can be encoded by using quotes:

MULTILINE="multiline\nencoded"

Options

Init takes these options:

typedef EnvOptions = {
	?overload: Bool, // Overwrite existing environment variables by the .env file
	?path: String,   // Specify a different path for loading the file
	?throws: Bool    // Defaults to true, throws if a variable is missing
}
Contributors
benmerckx
Version
0.0.0
Published
8 years ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub