# Environment variables API

The Azion Runtime Environment variables API gives a function the values of the environment variables stored on your Azion account. A variable keeps a configuration value or a secret out of the function code. Use it to connect to a database, a private API, or any other service that asks for credentials. You create and manage variables with [Azion CLI](/en/documentation/devtools/cli/), through the `azion create variables` command and its siblings. For more information, refer to [Environment variables](/en/documentation/platform/functions/environment-variables/).

> **Note**
>
> Under `azion dev`, a function reads the variables of the `.env` file in the project folder, not the variables stored on your account.

---

## Access

A function reads a variable with `Azion.env.get()`, which takes the key of the variable:

```javascript
const apiToken = Azion.env.get('API_SERVICE_TOKEN');
```

On a deployed function, the variables of your account are also properties of `process.env`:

```javascript
const apiToken = process.env.API_SERVICE_TOKEN;
```

The `env` argument of the `fetch(request, env, ctx)` handler carries no variables on a deployed function: it is an empty object. Read variables with `Azion.env.get()` or `process.env` instead.

> **Caution**
>
> Without a `.env` file in the project folder, `azion dev` passes the whole shell environment of your machine to the function as `env` and `process.env`. Any token or credential set in that shell becomes readable by the function code.

---

## Parameters

`Azion.env.get()` takes one parameter.

| Parameter | Type   | Description                  |
| --------- | ------ | ---------------------------- |
| `key`     | string | Key of the variable to read. |

---

## Return value

`Azion.env.get()` returns the value stored under the key, as a string. A variable created as a secret, with `--secret true`, returns its value the same way.

When the key matches no variable on your account, the call returns `undefined` and throws no error. A call that passes no key also returns `undefined`.

---

## Example

This function reads the `MY_VARIABLE` variable and returns its value as plain text, or a fallback string when the variable does not exist:

```javascript
export default {
  async fetch(request, env, ctx) {
    const value = Azion.env.get('MY_VARIABLE');

    return new Response(value || 'Variable not set', {
      headers: { 'content-type': 'text/plain' },
    });
  },
};
```

With `MY_VARIABLE` set to `my-value` on your account, a request to the deployed function returns:

```text
my-value
```

---

## Related resources

- [Environment variables](/en/documentation/platform/functions/environment-variables.md): The fields of a variable, the account limits, and the interfaces that manage variables.
- [Azion CLI variables](/en/documentation/devtools/cli/resources/variables.md): Every flag of the commands that create, list, describe, update, and delete variables.
- [Handlers](/en/documentation/devtools/runtime/api-reference/handlers.md): The handler shapes a function exports, and the arguments each one receives.
- [Develop and test a function locally](/en/documentation/platform/functions/local-development.md): How to give a function its variables through a `.env` file under `azion dev`.
