From 7a35567b45079f64d44a25a3040e311d177bfc68 Mon Sep 17 00:00:00 2001 From: dy0gu <103767860+dy0gu@users.noreply.github.com> Date: Mon, 24 Feb 2025 18:19:41 +0000 Subject: [PATCH] docs: improve command line environment variable tips (#16490) Co-authored-by: Michael H --- docs/guides/runtime/set-env.md | 13 ++++++++++++- docs/runtime/env.md | 32 +++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/docs/guides/runtime/set-env.md b/docs/guides/runtime/set-env.md index c336a2c7a5..2b36218af2 100644 --- a/docs/guides/runtime/set-env.md +++ b/docs/guides/runtime/set-env.md @@ -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. diff --git a/docs/runtime/env.md b/docs/runtime/env.md index ca0804818f..c77ba73089 100644 --- a/docs/runtime/env.md +++ b/docs/runtime/env.md @@ -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