# Envs

## [Environment Variables](https://docs.deno.com/runtime/reference/env_variables/)

There is built-in support for environment variables with `Deno.env`.

There are `getter` and `setter` methods.

```typescript
Deno.env.set("FIREBASE_API_KEY", "examplekey123");
Deno.env.set("FIREBASE_AUTH_DOMAIN", "firebasedomain.com");

console.log(Deno.env.get("FIREBASE_API_KEY")); // examplekey123
console.log(Deno.env.get("FIREBASE_AUTH_DOMAIN")); // firebasedomain.com
console.log(Deno.env.has("FIREBASE_AUTH_DOMAIN")); // true
```

#### Special Deno Environment Variables

Check [here](https://docs.deno.com/runtime/reference/env_variables/#special-environment-variables).

### `.env` Files

You can cause Deno to read environment variables from `.env` using the `--env-file` flag.

This will read `.env` by default.

```bash
deno run --env-file <script>
```

If you want or need to load environment variables from a different file, you can specify that file as a parameter to the flag.

```bash
deno run --env-file=.env.one --env-file=.env.two --allow-env <script>
```

{% hint style="warning" %}
When multiple declarations for the same environment variable exist within a single `.env` file, the first occurrence is applied.

However, if the same variable is defined across multiple `.env` files (using multiple `--env-file` arguments), the value from the last file specified takes precedence.
{% endhint %}
