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.localTyporithm · easy
Step 1 of 8 · intro card
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.
Bun auto-loads .env and .env.local — no dotenv needed.
Read via Bun.env or process.env; switch files with --env-file.
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 developmentConnect each part of the code to the concept before you type.
Bun reads .env and .env.local automatically — no dotenv package or require call needed.
bun run index.ts // auto-loads .env and .env.local--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 fileRead variables via Bun.env or the familiar process.env — both expose the loaded environment.
const url = Bun.env.DATABASE_URL // or process.env.DATABASE_URLbunfig.toml stores runtime config; when unset, Bun treats NODE_ENV as development.
// bunfig.toml holds runtime config; NODE_ENV defaults to developmentRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.