Skip to content

Latest commit

 

History

History
51 lines (31 loc) · 1.89 KB

readme.env.md

File metadata and controls

51 lines (31 loc) · 1.89 KB

Deno ENV

reference :=> doc

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

.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 config function from the standard library. Then, import the configuration using the config function.

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

const configData = await config(); const password = configData["PASSWORD"];

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

std/flags

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

import { load } from 'https://deno.land/[email protected]/dotenv/mod.ts'; /* DOTENV */
Deno.env.set('SOME_VAR', 'Value');
Deno.env.get('SOME_VAR'); // outputs "Value"
Deno.env.delete('SOME_VAR'); // outputs "undefined"
Deno.env.get('SOME_VAR'); // outputs "undefined"

const env = Deno.env.toObject(); // Record<string, string> // will contain all envs