> ## Documentation Index
> Fetch the complete documentation index at: https://bun.ll1025.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 读取环境变量

使用 `process.env` 访问当前环境变量。

```ts index.ts icon="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/typescript.svg?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=787d39d6a7d96d7f9540dc74344eba23" theme={null}
process.env.API_TOKEN; // => "secret"
```

***

Bun 还将这些变量暴露为 `Bun.env`，它是 `process.env` 的别名。

```ts index.ts icon="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/typescript.svg?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=787d39d6a7d96d7f9540dc74344eba23" theme={null}
Bun.env.API_TOKEN; // => "secret"
```

***

要打印所有当前设置的环境变量，请运行 `bun --print process.env`。

```sh terminal icon="terminal" theme={null}
bun --print process.env
```

```txt theme={null}
{
  BAZ: "stuff",
  FOOBAR: "aaaaaa",
  <还有很多行>
}
```

***

参见 [环境变量](/runtime/environment-variables)。
