using env vars in deno

by JIMz

1 min read

1. in shell / deno deploy / runtime

1a. define them

  • in shell, define and export them like
    export AWS_REGION="ap-southeast-1"
  • in deno deploy, define them in :
    project settings > environment variables
  • in run time : with the deno runtime API
    Deno.env.set(key: string, value: string): void
    official reference

1b. access them

with the deno runtime API

Deno.env.get(key: string): string | undefined

official reference

2. in .env file

1a. define them

put the file / symlink it to project root :

[project root]/.env

1b. access them

with deno standard library dotenv.

assuming an .env file like :


sameple codes to load it :

import { load } from "";
const env = await load();
const var_1 = env["VAR_1"];

some more official references( but they somehow interchange all of the above here and there and made them slightly confusing ).