import { type Deno } from "https://deno.land/x/deno@v1.28.0/cli/dts/lib.deno.ns.d.ts";
const { Env } = Deno;
An interface containing methods to interact with the process environment variables.
Methods
Retrieve the value of an environment variable.
Returns undefined
if the supplied environment variable is not defined.
console.log(Deno.env.get("HOME")); // e.g. outputs "/home/alice"
console.log(Deno.env.get("MADE_UP_VAR")); // outputs "undefined"
Requires allow-env
permission.
Set the value of an environment variable.
Deno.env.set("SOME_VAR", "Value");
Deno.env.get("SOME_VAR"); // outputs "Value"
Requires allow-env
permission.
Delete the value of an environment variable.
Deno.env.set("SOME_VAR", "Value");
Deno.env.delete("SOME_VAR"); // outputs "undefined"
Requires allow-env
permission.
Returns a snapshot of the environment variables at invocation as a simple object of keys and values.
Deno.env.set("TEST_VAR", "A");
const myEnv = Deno.env.toObject();
console.log(myEnv.SHELL);
Deno.env.set("TEST_VAR", "B");
console.log(myEnv.TEST_VAR); // outputs "A"
Requires allow-env
permission.