UNPKG

@accounter/server

Version:

The test suite is split into three Vitest projects for efficiency and isolation:

34 lines (33 loc) 1.29 kB
/** * Write or update an environment variable in a .env file * * Uses atomic write pattern (temp file + rename) to prevent corruption * if process crashes during write. * * ⚠️ **SECURITY WARNING**: This function stores values in PLAINTEXT. * Never use for production secrets. Use environment variables, * secret managers (AWS Secrets Manager, Vault), or encrypted files. * * **Thread Safety**: Not safe for concurrent writes to the same file. * Multiple processes writing simultaneously may cause race conditions. * * **Format Assumptions**: Assumes KEY=VALUE format without quotes or inline comments. * * @param filePath - Path to the .env file * @param key - Environment variable key (uppercase recommended) * @param value - Environment variable value (stored as-is) * * @example * ```typescript * // Create new variable * await writeEnvVar('.env', 'DATABASE_URL', 'postgresql://localhost/mydb'); * * // Update existing variable * await writeEnvVar('.env', 'DATABASE_URL', 'postgresql://localhost/newdb'); * * // Result is idempotent * await writeEnvVar('.env', 'API_KEY', 'abc123'); * await writeEnvVar('.env', 'API_KEY', 'abc123'); // No change * ``` */ export declare function writeEnvVar(filePath: string, key: string, value: string): Promise<void>;