Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno/cli/dts/lib.deno.ns.d.ts>Deno.Env

A modern runtime for JavaScript and TypeScript.
Go to Latest
interface Deno.Env
allow-env
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

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.

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.