Last active
June 11, 2025 14:20
-
-
Save TheAngryByrd/6ac79b2dda6c002f9cfc588c8d1b463f to your computer and use it in GitHub Desktop.
Basic .env file reader in F#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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