Skip to main content

Environment variables

There are a few ways to use environment variables in Deno:

Built-in Deno.env

The Deno runtime offers built-in support for environment variables with Deno.env.

Deno.env has getter and setter methods. Here is example usage:

Deno.env.set("FIREBASE_API_KEY", "examplekey123");
Deno.env.set("FIREBASE_AUTH_DOMAIN", "firebasedomain.com");

console.log(Deno.env.get("FIREBASE_API_KEY")); // examplekey123
console.log(Deno.env.get("FIREBASE_AUTH_DOMAIN")); // firebasedomain.com
console.log(Deno.env.has("FIREBASE_AUTH_DOMAIN")); // true

.env file

You can also put environment variables in a .env file and retrieve them using dotenv in the standard library.

Let's say you have an .env file that looks like this:

PASSWORD=Geheimnis

To access the environment variables in the .env file, import the load function from the standard library. Then, import the configuration using it.

import { load } from "https://deno.land/std@0.220.0/dotenv/mod.ts";

const env = await load();
const password = env["PASSWORD"];

console.log(password);
// "Geheimnis"

std/cli

The Deno standard library has a std/cli module for parsing command line arguments.

Special environment variables

The Deno runtime has these special environment variables.

namedescription
DENO_AUTH_TOKENSA semi-colon separated list of bearer tokens and hostnames to use when fetching remote modules from private repositories
(e.g. abcde12345@deno.land;54321edcba@github.com)
DENO_TLS_CA_STOREComma-separated list of order dependent certificate stores.
Possible values: system, mozilla. Defaults to mozilla.
DENO_CERTLoad certificate authority from PEM encoded file
DENO_DIRSet the cache directory
DENO_INSTALL_ROOTSet deno install's output directory (defaults to $HOME/.deno/bin)
DENO_REPL_HISTORYSet REPL history file path History file is disabled when the value is empty
(defaults to $DENO_DIR/deno_history.txt)
DENO_NO_PACKAGE_JSONDisables auto-resolution of package.json
DENO_NO_PROMPTSet to disable permission prompts on access
(alternative to passing --no-prompt on invocation)
DENO_NO_UPDATE_CHECKSet to disable checking if a newer Deno version is available
DENO_V8_FLAGSSet V8 command line options
DENO_JOBSNumber of parallel workers used for the --parallel flag with the test subcommand.
Defaults to number of available CPUs.
HTTP_PROXYProxy address for HTTP requests (module downloads, fetch)
HTTPS_PROXYProxy address for HTTPS requests (module downloads, fetch)
NPM_CONFIG_REGISTRYURL to use for the npm registry.
NO_COLORSet to disable color
NO_PROXYComma-separated list of hosts which do not use a proxy (module downloads, fetch)

You can also view the same content with deno --help.