denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
96.6k stars 5.33k forks source link

How to use env vars? #974

Closed reggi closed 6 years ago

reggi commented 6 years ago
console.log(deno.env('EXAMPLE'))

running with:

EXAMPLE=true deno --allow-env ./file.ts
reggi commented 6 years ago

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

ry commented 6 years ago
import { env } from "deno";
console.log(env()["EXAMPLE"])
brandonros commented 4 years ago
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

lucacasonato commented 4 years ago

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

kitsonk commented 4 years ago

So:

const env = Deno.env();
console.log(env["EXAMPLE"]);
// or
console.log(Deno.env("EXAMPLE"));
brundonsmith commented 4 years ago

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

main_ts_—_jlox
kitsonk commented 4 years ago

Use an editor plugin: https://deno.land/manual/getting_started/setup_your_environment#editors-and-ides

brundonsmith commented 4 years ago

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.