Structure
DotEnvFile
Reads dotenv (
.env) files and loads them into the current process.struct DotEnvFile
Overview
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.
Topics
Structures
struct LineRepresents aKEY=VALUEpair in a dotenv file.
Instance Properties
let lines: [DotEnvFile.Line]AllKEY=VALUEpairs found in the file.
Instance Methods
func load(overwrite: Bool)Loads this file’sKEY=VALUEpairs into the current process.
Type Methods
static func load(for: Environment, fileio: NonBlockingFileIO, logger: Logger) asyncReads the dotenv files relevant to the environment and loads them into the process.static func load(for: Environment, on: Application.EventLoopGroupProvider, fileio: NonBlockingFileIO, logger: Logger)Reads the dotenv files relevant to the environment and loads them into the process.static func load(for: Environment, on: Application.EventLoopGroupProvider, logger: Logger)Reads the dotenv files relevant to the environment and loads them into the process.static func load(path: String, fileio: NonBlockingFileIO, logger: Logger) asyncReads the dotenv files relevant to the environment and loads them into the process.static func load(path: String, fileio: NonBlockingFileIO, on: any EventLoop, overwrite: Bool) -> EventLoopFuture<Void>Reads a dotenv file from the supplied path and loads it into the process.static func load(path: String, fileio: NonBlockingFileIO, overwrite: Bool) async throwsReads a dotenv file from the supplied path and loads it into the process.static func load(path: String, on: Application.EventLoopGroupProvider, fileio: NonBlockingFileIO, logger: Logger)Reads the dotenv files relevant to the environment and loads them into the process.static func load(path: String, on: Application.EventLoopGroupProvider, logger: Logger)Reads the dotenv files relevant to the environment and loads them into the process.static func read(path: String, fileio: NonBlockingFileIO) async throws -> DotEnvFileReads a dotenv file from the supplied path.static func read(path: String, fileio: NonBlockingFileIO, on: any EventLoop) -> EventLoopFuture<DotEnvFile>Reads a dotenv file from the supplied path.
Relationships
Conforms To
Swift.SendableSwift.SendableMetatype