Deno: How to use env vars?

Created on 12 Oct 2018  路  8Comments  路  Source: denoland/deno

console.log(deno.env('EXAMPLE'))

running with:

EXAMPLE=true deno --allow-env ./file.ts

Most helpful comment

import { env } from "deno";
console.log(env()["EXAMPLE"])

All 8 comments

is giving back "Cannot find name 'deno'."

import { env } from "deno";
console.log(env()["EXAMPLE"])
import { env } from 'deno';

yields

error: Uncaught URIError: relative import path "deno" not prefixed with / or ./ or ../ Imported from "file:///app/index.ts"

looks like deno fetch doesn't know to skip the deno import

The deno namespace has moved to the Deno global. Use Deno.env()

So:

const env = Deno.env();
console.log(env["EXAMPLE"]);
// or
console.log(Deno.env("EXAMPLE"));

Is there a way to get your editor to recognize the Deno global?

main_ts_鈥擾jlox

Ah. I was using a different Deno plugin (by "axetroy") which I'm pretty sure was linked from somewhere else in the docs, though I can't find the reference now. This new one worked, thanks.

Was this page helpful?
0 / 5 - 0 ratings