Skip to content

Commit

Permalink
Environment Variables (#7306)
Browse files Browse the repository at this point in the history
* Environment variables

* .
  • Loading branch information
RiskyMH committed Nov 25, 2023
1 parent 5f86b83 commit 6517252
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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

0 comments on commit 6517252

Please sign in to comment.