env/update_env_variable.ts view source
(key: string, value: string, options: UpdateEnvVariableOptions): Promise<void> Updates or adds an environment variable in the .env file. Preserves existing formatting, comments, and other variables.
Behavior:
- Duplicate keys: updates the LAST occurrence (matches dotenv behavior)
- Inline comments: preserved after the value (e.g., KEY=value # comment)
- Quote style: preserved from original (quoted/unquoted)
key
the environment variable name (e.g., 'SOME_CONFIGURATION_KEY')
stringvalue
the new value for the environment variable
stringoptions
file path and optional read/write overrides
returns
Promise<void> throws
Error- if the file read fails for any reason other than `ENOENT`, or if the write fails