Skip to main content
Version: 4.0.0

env

The env() function returns the value for the provided environment variable name.

For a list of available environment variables, see the Fastly Developer Hub for Compute Environment Variables

Note: The environment variables can only be retrieved when processing requests, not during build-time initialization.

Syntax​

env(name)

Parameters​

  • name : string
    • The name of the environment variable to retrieve

Return value​

The value for the requested environment variable, if no such environment variable exists then undefined is returned.

Examples​

In this example we log to stdout the environment variables FASTLY_HOSTNAME and FASTLY_TRACE_ID.

/// <reference types="@fastly/js-compute" />
import { env } from "fastly:env";
function app(event) {
console.log("FASTLY_HOSTNAME:", env("FASTLY_HOSTNAME"));
console.log("FASTLY_TRACE_ID:", env("FASTLY_TRACE_ID"));
return new Response("", {
status: 200
});
}
addEventListener("fetch", event => event.respondWith(app(event)));