> ## Documentation Index
> Fetch the complete documentation index at: https://bun.manicule.dev/llms.txt
> Use this file to discover all available pages before exploring further.
> For every page in one file, fetch https://bun.manicule.dev/llms-full.txt (large).
> To search and read these docs as tools, connect the MCP server at https://bun.manicule.dev/api/mcp.
> Every agent surface: https://bun.manicule.dev/.well-known/llms-manifest.json

# Set environment variables (/guides/runtime/set-env)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 227 · updated: 2026-08-02 -->
Related: [Delete directories](/guides/runtime/delete-directory.md), [Delete files](/guides/runtime/delete-file.md), [Import a HTML file as text](/guides/runtime/import-html.md), [Import a JSON file](/guides/runtime/import-json.md), [Import a JSON5 file](/guides/runtime/import-json5.md), [Import a TOML file](/guides/runtime/import-toml.md)

Access the current environment variables with `process.env` or `Bun.env`.

```ts icon="/icons/typescript.svg" title="index.ts"
Bun.env.API_TOKEN; // => "secret"
process.env.API_TOKEN; // => "secret"
```

***

Set these variables in a `.env` file.

Bun reads the following files automatically (listed in order of increasing precedence).

* `.env`
* `.env.production`, `.env.development`, `.env.test` (depending on value of `NODE_ENV`)
* `.env.local` (not loaded when `NODE_ENV=test`)

```ini icon="settings" title=".env"
FOO=hello
BAR=world
```

***

You can also set variables on the command line.

<CodeGroup>
```sh title="Linux/macOS" icon="terminal"
FOO=helloworld bun run dev
```

```sh title="Windows" icon="windows"
# Using CMD
set FOO=helloworld && bun run dev

# Using PowerShell
$env:FOO="helloworld"; bun run dev
```
</CodeGroup>

***

See [Environment variables](/runtime/environment-variables).
