https://deno.land/x/dotenv 

Dotenv Build Status

Dotenv handling for deno.

Usage

Setup a .env file in the root of your project.

# .env
GREETING=hello world

Then import the configuration using the config function.

// app.ts
import { config } from "https://deno.land/x/dotenv/dotenv.ts";

console.log(config());

Then run your app.

> deno app.ts
{ GREETING: "hello world" }

Options

Auto loading

load.ts automatically loads the local .env file on import and exports it to the process environment:

# .env
GREETING=hello world
// app.ts
import "https://deno.land/x/dotenv/load.ts";
import { env } from "deno";

console.log(env().GREETING);
> deno --allow-env app.ts
hello world

Safe Mode

To enable safe mode, create a .env.example file in the root of the project.

# .env.example
GREETING=

Then import the configuration with safe option set to true.

// app.ts
import { config } from "https://deno.land/x/dotenv/dotenv.ts";

console.log(config({ safe: true }));

If any of the defined variables is not in .env, an error will occur. This method is preferred because it prevents runtime errors in a production application due to improper configuration.

Another way to suply required variables is externally, like so:

GREETING="hello world" deno --allow-env app.ts

Parsing Rules

The parsing engine currently supports the following rules:

{MULTILINE: 'new
line'}

Contributing

Issues and pull requests welcome. Please run make fmt before commiting.

Credit