jose
jose
DDeno
Created by jose on 12/29/2023 in #help
Environment Variable always returns undefined
I'm just trying to import the values from dotenv to the code, but it always returns undefined. deno version: 1.39.1 running command: deno run --allow-read --allow-env main.ts dotenv content:
FOO=123
FOO=123
main.ts content:
import "https://deno.land/std@0.208.0/dotenv/load.ts";
console.log(Deno.env.get("FOO"));
import "https://deno.land/std@0.208.0/dotenv/load.ts";
console.log(Deno.env.get("FOO"));
I also tried
import { load } from "https://deno.land/std@0.210.0/dotenv/mod.ts";

await load({
export:true,
envPath: "./.env",
allowEmptyValues: false,
});

const test = Deno.env.get("TEST_TOKEN")
console.log(test)
import { load } from "https://deno.land/std@0.210.0/dotenv/mod.ts";

await load({
export:true,
envPath: "./.env",
allowEmptyValues: false,
});

const test = Deno.env.get("TEST_TOKEN")
console.log(test)
result is always:
Task start deno run --allow-read --allow-env main.ts
undefined
Task start deno run --allow-read --allow-env main.ts
undefined
Update: also tried deno run --env --allow-env main.ts and it still is undefined.
21 replies