Skip to content

Environment variables

The proper place to store secrets, keys, and API tokens is in Environment Variables. When you add a key and value to the list of environment variables on that page, it becomes available via the Deno.env and process.env variables.

Environment variables can be accessed via Deno.env or process.env.

Deno.env

This uses the Deno-default Deno.env variable, which is available globally.

use-deno-env.ts
export let sdk = new SomeSDK(Deno.env.get("someSdkSecret"));

process.env

This is the conventional way to access environment variables when you’re in a Node.js environment. In Node.js, process is an always-available global variable, but since Val Town targets Deno, you’ll need to import process from node:process:

import-process.ts
import process from "node:process";
export let sdk = new SomeSDK(process.env.someSdkSecret);

Notes

  • Vals can’t set environment variables: Environment variables are set via the settings page. Trying to update an environment variable, for example by using Deno.env.set, is a no-op.