Typorithm · easy

Env & bunfig

bun-env-configbunenvdotenvbunfig
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Env & bunfig

0%

Bun Runtime

Bun auto-loads .env and .env.local with no dotenv package. Read values via Bun.env or process.env, point at another file with --env-file=.env.prod, store runtime config in bunfig.toml, and rely on NODE_ENV defaulting to development.

Bun automatically loads .env and .env.local at startup, so you never need the dotenv package — the variables are available immediately via Bun.env or process.env.

To use a different file, pass bun --env-file=.env.prod; this is handy for swapping in production or staging values without changing code.

Runtime configuration that is not an environment variable lives in bunfig.toml, and Bun follows the usual convention of treating NODE_ENV as development when it is not explicitly set.

01

Bun auto-loads .env and .env.local — no dotenv needed.

02

Read via Bun.env or process.env; switch files with --env-file.

03

bunfig.toml holds runtime config; NODE_ENV defaults to development.

bun run index.ts                 // auto-loads .env and .env.local
bun --env-file=.env.prod run app.ts  // load a specific env file
const url = Bun.env.DATABASE_URL  // or process.env.DATABASE_URL
// bunfig.toml holds runtime config; NODE_ENV defaults to development

Read the implementation

Connect each part of the code to the concept before you type.

1. Auto-load .env

Bun reads .env and .env.local automatically — no dotenv package or require call needed.

bun run index.ts                 // auto-loads .env and .env.local

2. Custom env file

--env-file points Bun at a specific file, e.g. .env.prod, instead of the defaults.

bun --env-file=.env.prod run app.ts  // load a specific env file

3. Read a var

Read variables via Bun.env or the familiar process.env — both expose the loaded environment.

const url = Bun.env.DATABASE_URL  // or process.env.DATABASE_URL

4. bunfig & NODE_ENV

bunfig.toml stores runtime config; when unset, Bun treats NODE_ENV as development.

// bunfig.toml holds runtime config; NODE_ENV defaults to development

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Env & bunfig: Lesson & Practice · Typorithm | ApplyDjinn