Skip to content

Type Method

read(path:fileio:)

Reads a dotenv file from the supplied path.
static func read(path: String, fileio: NonBlockingFileIO) async throws -> DotEnvFile

Parameters

path

Absolute or relative path of the dotenv file.

fileio

File loader.

Discussion

let fileio: NonBlockingFileIO
let file = try await DotEnvFile.read(path: ".env", fileio: fileio)
for line in file.lines {
    print("\(line.key)=\(line.value)")
}
file.load(overwrite: true) // loads all lines into the process
print(Environment.process.FOO) // BAR

Use DotEnvFile.load to read and load with one method.