server/env_file_helpers.ts

Declarations
#

2 declarations

view source

update_env_variable
#

server/env_file_helpers.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')

type string

value

- The new value for the environment variable

type string

options

- Optional configuration for file path and operations

default {}

returns

Promise<void>

UpdateEnvVariableOptions
#

server/env_file_helpers.ts view source

UpdateEnvVariableOptions

Options for updating environment variables in a .env file.

env_file_path

Path to the .env file (defaults to ./.env)

type string

read_file

Function to read file contents (defaults to node:fs/promises readFile)

type (path: string, encoding: string) => Promise<string>

write_file

Function to write file contents (defaults to node:fs/promises writeFile)

type (path: string, content: string, encoding: string) => Promise<void>

Imported by
#