aboutsummaryrefslogtreecommitdiff
path: root/docs/runtime
diff options
context:
space:
mode:
authorGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-10-02 17:52:29 -0700
committerGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-10-02 17:52:29 -0700
commit63a00791faac5636394f38f540f79d2e452b6b65 (patch)
tree769afaaff6710d3bf636fd7c60991ed482784562 /docs/runtime
parenta6af1c89b954c56493d457d33b7f066e1f195afa (diff)
downloadbun-63a00791faac5636394f38f540f79d2e452b6b65.tar.gz
bun-63a00791faac5636394f38f540f79d2e452b6b65.tar.zst
bun-63a00791faac5636394f38f540f79d2e452b6b65.zip
Update development and document env var expansion
Diffstat (limited to 'docs/runtime')
-rw-r--r--docs/runtime/env.md40
1 files changed, 39 insertions, 1 deletions
diff --git a/docs/runtime/env.md b/docs/runtime/env.md
index 7fcfd98aa..e38eabffd 100644
--- a/docs/runtime/env.md
+++ b/docs/runtime/env.md
@@ -25,9 +25,47 @@ Or programmatically by assigning a property to `process.env`.
process.env.FOO = "hello";
```
+### Quotation marks
+
+Bun supports double quotes, single quotes, and
+
+### Expansion
+
+Environment variables are automatically _expanded_. This means you can reference previously-defined variables in your environment variables.
+
+```txt#.env
+FOO=world
+BAR=hello$FOO
+```
+
+```ts
+process.env.BAR; // => "helloworld"
+```
+
+This is useful for constructing connection strings or other compound values.
+
+```txt#.env
+DB_USER=postgres
+DB_PASSWORD=secret
+DB_HOST=localhost
+DB_PORT=5432
+DB_URL=postgres://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME
+```
+
+This can be disabled by escaping the `$` with a backslash.
+
+```txt#.env
+FOO=world
+BAR=hello\$FOO
+```
+
+```ts
+process.env.BAR; // => "hello$FOO"
+```
+
### `dotenv`
-Generally speaking, you won't need `dotenv` anymore, because Bun reads `.env` files automatically.
+Generally speaking, you won't need `dotenv` or `dotenv-expand` anymore, because Bun reads `.env` files automatically.
## Reading environment variables