pietvanzoen / deno-dotenv

Deprecated. Use std/dotenv instead.
https://deno.land/std/dotenv/
MIT License
148 stars 9 forks source link

dotenv does not load variables to Deno.env #50

Closed tymfear closed 3 years ago

tymfear commented 3 years ago

deno --version output

deno 1.12.2 (release, x86_64-apple-darwin)
v8 9.2.230.14
typescript 4.3.5

.env file

# .env
HELLOWORLD=hello world

testenv.ts

import { config } from "https://deno.land/x/dotenv@v2.0.0/mod.ts";

console.log(Deno.env.get("HELLOWORLD"));
console.log(config());

output of deno run -A testenv.ts

undefined
{ HELLOWORLD: "hello world" }

Though it loads it to the config method output

pietvanzoen commented 3 years ago

config doesn’t export to to Deno.env by default. But you can pass a flag to enable that. Also be sure to call config before trying to access the variable via Deno.env.


import { config } from "https://deno.land/x/dotenv@v2.0.0/mod.ts";

console.log(config({ export: true }));
console.log(Deno.env.get("HELLOWORLD"));

alternatively you can auto load the variables into Deno.env: https://github.com/pietvanzoen/deno-dotenv#auto-loading

// app.ts
import "https://deno.land/x/dotenv/load.ts";

console.log(Deno.env.get("GREETING"));

I hope this helps. Let me know how you get on. :)

tymfear commented 3 years ago

@pietvanzoen , that helped, thanks! Haven't seen the difference in import URL for load and config.