DotEnvFile
Reads dotenv (.env
) files and loads them into the current process.
struct DotEnvFile
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
Dotenv files are formatted using KEY=VALUE
syntax. They support comments using the #
symbol. They also support strings, both single and double-quoted.
FOO=BAR
STRING='Single Quote String'
# Comment
STRING2="Double Quoted\nString"
Single-quoted strings are parsed literally. Double-quoted strings may contain escaped newlines that will be converted to actual newlines.