Skip to content

Instantly share code, notes, and snippets.

@TheAngryByrd
Last active June 11, 2025 14:20
Show Gist options
  • Save TheAngryByrd/6ac79b2dda6c002f9cfc588c8d1b463f to your computer and use it in GitHub Desktop.
Save TheAngryByrd/6ac79b2dda6c002f9cfc588c8d1b463f to your computer and use it in GitHub Desktop.
Basic .env file reader in F#
namespace FsToolkit.Build
module DotEnv =
open System
open System.IO
let private parseLine (line: string) =
match line.Split('=', StringSplitOptions.RemoveEmptyEntries) with
| args when args.Length = 2 -> Environment.SetEnvironmentVariable(args.[0], args.[1])
| _ -> ()
let load (rootDir) =
let filePath = Path.Combine(rootDir, ".env")
if File.Exists filePath then
filePath
|> File.ReadAllLines
|> Seq.iter parseLine
else
printfn "No .env file found. %s" rootDir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment