# Environment variables

Store the configuration your app reads when it builds and runs.

The **Environment** view lists the variables in your project's `.env` files. Add, edit, copy and delete them without opening the files.

The Environment view listing VITE\_ variables with hidden values, one value shown, and the Add variable form at the bottom.

## What you can do

- See the variables of `.env`, `.env.local` and `.env.development` in one list.
- Show or hide a value, and copy it.
- Edit a value in place.
- Delete a variable.
- Add a new variable to `.env`.

## Add a variable

1. ### Open Environment

   In **Code** mode, choose **Environment** in the views rail.
2. ### Enter the name and value

   At the bottom of the view, type the name in **KEY** and the value in **value**. Names use letters, digits and underscores, and cannot start with a digit.
3. ### Add it

   Choose **Add variable**. The variable is added to `.env`, and the line under the form confirms it with its name. If the file does not exist yet, Lyna creates it. A name already in `.env` is not added twice: the line under the form says so, and you change its value in the list instead.

Values are hidden by default. Choose **Show value** to see one and **Copy value** to copy it. Use the edit button to change a value in place, and the delete button to remove the variable.

## Use a variable in your app

The build only gives the browser code the variables whose name starts with `VITE_`. Read them with `import.meta.env`:

```tsx
const apiUrl = import.meta.env.VITE_API_URL;
```

A variable without the `VITE_` prefix is not available in your pages.

> [!WARNING]
>
> **Never put a private key in .env**
>
> Everything your pages can read ends up in the code your visitors download. Keep private keys, such as payment secret keys or AI API keys, in **Edge Functions** secrets and use them from an edge function. See [Secrets](/features/cloud/secrets).

## FAQ

### I changed a variable and the preview did not change

Reload the preview. If the value still looks old, choose **Restart Dev Server** in the [Terminal](/features/code/terminal).

### What is the difference with the Secrets page?

This view edits the `.env` files of your app. The **Secrets** page in **Settings > Lyna Cloud** manages the same app values plus the private secrets of your edge functions.

## Related

- [Secrets](/features/cloud/secrets): Private keys for your edge functions.
- [Edge functions](/features/cloud/edge-functions): Run server code that uses private keys.
- [Packages](/features/code/packages): Add the libraries your app needs.
