Parse a .env file into a key-value object.
(filePath)
| 11 | |
| 12 | /** Parse a .env file into a key-value object. */ |
| 13 | function parseEnvFile(filePath) { |
| 14 | const vars = {}; |
| 15 | if (!existsSync(filePath)) return vars; |
| 16 | |
| 17 | for (const line of readFileSync(filePath, 'utf-8').split('\n')) { |
| 18 | const trimmed = line.trim(); |
| 19 | if (!trimmed || trimmed.startsWith('#')) continue; |
| 20 | const eqIdx = trimmed.indexOf('='); |
| 21 | if (eqIdx === -1) continue; |
| 22 | vars[trimmed.slice(0, eqIdx)] = trimmed.slice(eqIdx + 1); |
| 23 | } |
| 24 | return vars; |
| 25 | } |
| 26 | |
| 27 | const envFile = parseEnvFile('.env.local'); |
| 28 |