Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment Variables #7306

Merged
merged 3 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/api/import-meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ import.meta.resolveSync("zod")

---

- `import.meta.env`
- An alias to `process.env`.

---

- `import.meta.resolve{Sync}`
- Resolve a module specifier (e.g. `"zod"` or `"./file.tsx"`) to an absolute path. While file would be imported if the specifier were imported from this file?

Expand Down
13 changes: 12 additions & 1 deletion docs/runtime/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ Or programmatically by assigning a property to `process.env`.
process.env.FOO = "hello";
```

### Manually specifying `.env` files

Bun supports `--env-file` to override which specific `.env` file to load. You can use `--env-file` when running scripts in bun's runtime, or when running package.json scripts.

```sh
bun --env-file=.env.1 src/index.ts

bun --env-file=.env.abc --env-file=.env.def run build
```

### Quotation marks

Bun supports double quotes, single quotes, and
Expand Down Expand Up @@ -75,10 +85,11 @@ The current environment variables can be accessed via `process.env`.
process.env.API_TOKEN; // => "secret"
```

Bun also exposes these variables via `Bun.env`, which is a simple alias of `process.env`.
Bun also exposes these variables via `Bun.env` and `import.meta.env`, which is a simple alias of `process.env`.

```ts
Bun.env.API_TOKEN; // => "secret"
import.meta.env.API_TOKEN; // => "secret"
```

To print all currently-set environment variables to the command line, run `bun run env`. This is useful for debugging.
Expand Down