Envious - a simple env parser written with NimbleParsec

Last year at Jax.Ex (Jacksonville Elixir Meetup) we live mob coded the start of a dotenv parser to learn NimbleParsec. It’s been on my list of things to complete for a while. Today Claude Code helped me finish the outstanding issues.

Features

  • Comments: Lines starting with # are ignored
  • Export prefix: Optional export keyword (shell compatibility)
  • Quoted values: Single and double quotes with escape sequences
  • Multi-line values: Quoted values can span multiple lines
  • Empty values: KEY= produces an empty string
  • Digits in keys: Variable names like DB2_HOST, API_V2_URL are supported
  • Escape sequences: \n, \t, \r, \\, \", \' in quoted strings
  • Blank lines: Multiple blank lines and trailing whitespace are handled correctly

You can use it like this:

# config/runtime.exs
import Config

# Load environment-specific .env file if it exists
env_file = ".#{config_env()}.env"

if File.exists?(env_file) do
  env_file |> File.read!() |> Envious.parse!() |> System.put_env()
end

# Do your normal 12-factor things
config :my_app,
  key1: System.get_env("KEY1"),
  key2: System.get_env("KEY2")

Hope you find it useful. :slight_smile:

4 Likes

Add an issue to Enviable and I’ll add a reference to Envious since I mention both nvir and dotenvy.

1 Like