---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---
import {Fiddle} from '@site/src/components/fiddle';

# 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](https://developer.fastly.com/reference/compute/ecp-env/)

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

## Syntax

```js
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 an empty string is returned.

## Examples

In this example we log to stdout the environment variables [`FASTLY_HOSTNAME`](https://developer.fastly.com/reference/compute/ecp-env/fastly-hostname/) and [`FASTLY_TRACE_ID`](https://developer.fastly.com/reference/compute/ecp-env/fastly-trace-id/).

<Fiddle config={{
  "type": "javascript",
  "title": "env Example",
  "origins": [
    "https://http-me.fastly.dev"
  ],
  "src": {
    "deps": "{\n  \"@fastly/js-compute\": \"^1.0.1\"\n}",
    "main": `
/// <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)));
`
  },
  "requests": [
    {
      "enableCluster": true,
      "enableShield": false,
      "enableWAF": false,
      "data": {
         "dictionaries": {
           "animals": {
             "cat": "meow"
           }
         }
       },
      "method": "GET",
      "path": "/status=200",
      "useFreshCache": false,
      "followRedirects": false,
      "tests": "",
      "delay": 0
    }
  ],
  "srcVersion": 1
}}>

```js
/// <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)));
```

</Fiddle>