Created
January 6, 2026 18:47
-
-
Save franky47/9ce6eaf80b4c74b63988370b7c39fd23 to your computer and use it in GitHub Desktop.
loadEnv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { loadEnvFile } from 'node:process' | |
| export function loadEnv() { | |
| const nodeEnv = process.env.NODE_ENV || 'development' | |
| // Load in order of precedence | |
| const files = [ | |
| `.env.${nodeEnv}.local`, | |
| nodeEnv === 'test' ? null : `.env.local`, | |
| `.env.${nodeEnv}`, | |
| `.env`, | |
| ].filter((file): file is string => !!file) | |
| for (const file of files) { | |
| try { | |
| loadEnvFile(file) | |
| break // Stop after the first successful load | |
| } catch {} | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment