Syntax
| 1 | |
| 2 | PORT=3000 |
| 3 | CHAT_URL=https://chat.xpulse.one |
| 4 | |
| 5 | |
| 6 | APP_NAME="xPulse Web" |
| 7 | APP_NAME='xPulse Web' |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | GREETING="Hello World" |
| 13 | |
| 14 | |
| 15 | SECRET=abc=123=xyz |
Rules
- Existing
process.env values are not overridden β system env takes precedence
- Comments (
#) and empty lines are ignored
- Quotes (
" and ') are stripped from values
- No interpolation β
${VAR} in .env is not resolved (that is handled by @xpulse/config)
- Equals signs in values are allowed (only the first
= separates key and value)
Multiple Files
| 1 | .env β base, always loaded |
| 2 | .env.stage β overrides .env values for stage |
| 3 | .env.production β overrides .env values for production |
Values in .env.{env} take precedence over .env. Missing files are silently ignored.
Example
| 1 | |
| 2 | PORT=3000 |
| 3 | LOG_LEVEL=info |
| 4 | APP_URL=http://localhost:3000 |
| 1 | |
| 2 | APP_URL=https://rc-2-0-0.stage.xpulse.one |
| 3 | LOG_LEVEL=debug |
Result after dotenv.load({ env: 'stage' }):
| 1 | PORT=3000 β from .env |
| 2 | LOG_LEVEL=debug β from .env.stage (overridden) |
| 3 | APP_URL=https://rc-2-0-0.stage.xpulse.one β from .env.stage (overridden) |