---
title: env
summary: Function to get the value for the provided environment variable name.
url: https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/env/fn.env/
---

**Kind:** Function  
**Module:** [env](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/env/)  
**Package:** @fastly/js-compute 4.0.1  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/env.d.ts#L62

```javascript
env(name: string): string | undefined
```

Function to get 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.

**Parameters**

- `name`: `string` — The name of the environment variable

**Returns**

`string | undefined`

The value of the environment variable, or `undefined` if no such environment variable exists.

````javascript
<script async defer src="https://fiddle.fastly.dev/embed.js"></script>
In this example we log to stdout the environment variables `FASTLY_HOSTNAME` and `FASTLY_TRACE_ID`.

<script type="application/json+fiddle">
{
  "type": "javascript",
  "title": "Environment Variable Example",
  "origins": [
    "https://http-me.fastly.dev"
  ],
  "src": {
    "deps": "{\n  \"@fastly/js-compute\": \"^0.7.0\"\n}",
    "main": "/// <reference types=\"@fastly/js-compute\" />\nimport { env } from \"fastly:env\";\n\nfunction app(event) {\n  console.log(\"FASTLY_HOSTNAME:\", env(\"FASTLY_HOSTNAME\"));\n  console.log(\"FASTLY_TRACE_ID:\", env(\"FASTLY_TRACE_ID\"));\n\n  return new Response(\"\", {\n    status: 200\n  });\n}\n\naddEventListener(\"fetch\", event => event.respondWith(app(event)));\n"
  },
  "requests": [
    {
      "enableCluster": true,
      "enableShield": false,
      "enableWAF": false,
      "method": "GET",
      "path": "/status=200",
      "useFreshCache": false,
      "followRedirects": false,
      "tests": "",
      "delay": 0
    }
  ],
  "srcVersion": 26
}
</script>
<noscript>
```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)));
```
</noscript>
````
