interface Deno.Env
An interface containing methods to interact with the process environment variables.
get(key: string): string | undefined
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(key: string,value: string,): void
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(key: string): void
Delete the value of an environment variable.
Deno.env.set("SOME_VAR", "Value");
Deno.env.delete("SOME_VAR"); // outputs "undefined"
Requires allow-env
permission.
has(key: string): boolean
Check whether an environment variable is present or not.
Deno.env.set("SOME_VAR", "Value");
Deno.env.has("SOME_VAR"); // outputs true
Requires allow-env
permission.
toObject(): { [index: string]: string; }
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.