Environment Variables in Bun
From the Bun cheat sheet ยท Environment & Utilities ยท verified Jul 2026
Environment Variables
Access and manage environment variables with auto .env loading
typescript
// Access env vars (auto-loaded from .env)
const dbUrl = Bun.env.DATABASE_URL;
const port = Bun.env.PORT || "3000";
// Also available on process.env
const key = process.env.API_KEY;๐ก Bun auto-loads .env files with no dotenv package โ just create the file and go
โก Use bun --env-file to load a specific env file for different environments
๐ Both Bun.env and process.env work โ Bun.env is slightly faster as it skips Node compat
๐ข import.meta.dir/file/path give you the current file location โ no __dirname polyfill needed
envenvironmentdotenv