docs: improve command line environment variable tips (#16490)

Co-authored-by: Michael H <git@riskymh.dev>
This commit is contained in:
dy0gu
2025-02-24 18:19:41 +00:00
committed by GitHub
parent 47f9bb84e8
commit 7a35567b45
2 changed files with 43 additions and 2 deletions

View File

@@ -28,10 +28,21 @@ BAR=world
Variables can also be set via the command line.
```sh
{% codetabs %}
```sh#Linux/macOS
$ FOO=helloworld bun run dev
```
```sh#Windows
# Using CMD
$ set FOO=helloworld && bun run dev
# Using PowerShell
$ $env:FOO="helloworld"; bun run dev
```
{% /codetabs %}
---
See [Docs > Runtime > Environment variables](https://bun.sh/docs/runtime/env) for more information on using environment variables with Bun.

View File

@@ -15,10 +15,40 @@ BAR=world
Variables can also be set via the command line.
```sh
{% codetabs %}
```sh#Linux/macOS
$ FOO=helloworld bun run dev
```
```sh#Windows
# Using CMD
$ set FOO=helloworld && bun run dev
# Using PowerShell
$ $env:FOO="helloworld"; bun run dev
```
{% /codetabs %}
{% details summary="Cross-platform solution with Windows" %}
For a cross-platform solution, you can use [bun shell](https://bun.sh/docs/runtime/shell). For example, the `bun exec` command.
```sh
$ bun exec 'FOO=helloworld bun run dev'
```
On Windows, `package.json` scripts called with `bun run` will automatically use the **bun shell**, making the following also cross-platform.
```json#package.json
"scripts": {
"dev": "NODE_ENV=development bun --watch app.ts",
},
```
{% /details %}
Or programmatically by assigning a property to `process.env`.
```ts