An extremely simple library to support env files. This library is meant to be used with the basic environment variable support that Haskell has (System.Environment).
This package is not on hackage but cabal (and stack) let's you use packages that are on github. (I don't use stack so you will have to figure it out yourself)
- Create cabal.project file if you don't have one already at the root of your project.
Essentially at the same location as your .cabal file and put this in the cabal.project file.
packages: . source-repository-package type: git location: https://github.com/WildSource/env tag: v0.1.1.0
- Add the library to your .cabal file.
-- Other library packages from which modules are imported. build-depends: base ^>=4.20.0.0, env
- Execute the cabal update and cabal build commands and you should be good to go.
- import the library (import Env) and System.Environment (we need getEnv)
import Env
import System.Environment
- use the loadEnv or loadEnvFile function
loadEnv
or
loadEnvFile "pathToEnv.env"
- to get your values just use the getEnv "nameOfKey" from System.Environment
inside the env file -> HELLO=WORLD
getEnv "HELLO"
output
"WORLD"