{"id":32174516,"url":"https://github.com/dwyl/envar","last_synced_at":"2026-02-19T07:02:57.450Z","repository":{"id":31456683,"uuid":"35020525","full_name":"dwyl/envar","owner":"dwyl","description":"📂 envar helps check and get environment variables in Elixir","archived":false,"fork":false,"pushed_at":"2025-11-04T21:17:25.000Z","size":125,"stargazers_count":32,"open_issues_count":4,"forks_count":3,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-11-04T23:21:27.566Z","etag":null,"topics":["elixir","environment","environment-variables","variables"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dwyl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2015-05-04T07:27:24.000Z","updated_at":"2025-11-04T21:17:22.000Z","dependencies_parsed_at":"2023-02-15T02:46:01.189Z","dependency_job_id":"d0bc9379-799a-4e06-9e4c-c2e3f5cc9ff3","html_url":"https://github.com/dwyl/envar","commit_stats":{"total_commits":68,"total_committers":8,"mean_commits":8.5,"dds":0.5882352941176471,"last_synced_commit":"c8a2a606039e54d4e7769063f1b850468968ceda"},"previous_names":["dwyl/retriever"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/dwyl/envar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwyl%2Fenvar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwyl%2Fenvar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwyl%2Fenvar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwyl%2Fenvar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwyl","download_url":"https://codeload.github.com/dwyl/envar/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwyl%2Fenvar/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29605806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T06:47:36.664Z","status":"ssl_error","status_checked_at":"2026-02-19T06:45:47.551Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","environment","environment-variables","variables"],"created_at":"2025-10-21T19:01:49.465Z","updated_at":"2026-02-19T07:02:57.444Z","avatar_url":"https://github.com/dwyl.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n\u003cimg src=\"https://user-images.githubusercontent.com/194400/151025711-574482bb-918d-499f-b7cd-32bf224403c8.png\"\nalt=\"envar rainbow logo\"\u003e\n\nA collection of functions for checking/getting/setting **environment variables** in **`Elixir`**.\n\n\u003c!-- Better LOGO #HelpWanted --\u003e\n\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/dwyl/envar/ci.yml?label=build\u0026style=flat-square\u0026branch=main)](https://github.com/dwyl/envar/actions)\n[![codecov.io](https://img.shields.io/codecov/c/github/dwyl/envar/main.svg?style=flat-square)](https://codecov.io/github/dwyl/envar?branch=main)\n[![Hex.pm](https://img.shields.io/hexpm/v/envar?color=brightgreen\u0026style=flat-square)](https://hex.pm/packages/envar)\n[![Dependencies: None](https://img.shields.io/badge/dependencies-none-brightgreen.svg?style=flat-square)](https://libraries.io/hex/envar \"Zero Dependencies\")\n[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/envar/issues)\n[![HitCount](https://hits.dwyl.com/dwyl/envar.svg)](https://hits.dwyl.com/dwyl/envar)\n\n\u003c/div\u003e\u003cbr /\u003e\n\n## Why?\n\nWe needed a way of checking that environment variables were defined\nand improving the developer experience when they are not.\n\n## What?\n\n**`envar`** is our solution to a very specific problem:\nthe developer experience when a required environment variable is undefined.\n\n\u003cbr /\u003e\n\n## How?\n\n### Installation\n\nInstall the package\nby adding `envar` to your list of dependencies in your `mix.exs` file:\n\n```elixir\ndef deps do\n  [\n    {:envar, \"~\u003e 1.1.0\"}\n  ]\nend\n```\n\n## Usage\n\nLoad an `.env` file\ncontaining a line-separated list of environment variables\non your `localhost`:\n\n```elixir\nEnvar.load(\".env\")\n```\n\nThat will locate the `.env` file in your project\nand set each environment variable in it.\n\nIf the `.env` _must_ exist e.g. in a `:test` context,\ninvoke:\n\n```elixir\nEnvar.require_env_file(\".env\")\n```\n\nThat will log an `Error` if the file does not exist (or can't be found):\n\n```sh\n09:10:54.103 [error] Required .env file does not exist at path: /Alex/awesome/project/.env\n```\n\n\n\n\u003cbr /\u003e\n\nWhen you need to retrieve a specific environment variable,\nuse the following:\n\n```elixir\nDATABASE_URL = Envar.get(\"DATABASE_URL\")\n```\n\n\u003cbr /\u003e\n\nIf you want to define a default/fallback value\nfor the environment variable when it's not set,\nsimply add it as the second argument:\n\n```elixir\nDATABASE_URL = Envar.get(\"DATABASE_URL\", \"postgres://uname:pass@host:5432/dbname\"\")\n```\n\n\u003cbr /\u003e\n\nIf you need to check that a variable is set,\nuse `is_set?/1`\n\n```elixir\nif Envar.is_set?(\"Heroku\") do\n  # do stuff on Heroku\nend\n```\n\nTo check if _any_ of the variables in a `List` are set,\ninvoke `Envar.is_set_any?/1`:\n\n```elixir\nif Envar.is_set_any?(~w/HEROKU FLYIO/) do\n  # Do something on non-prod environment\nend\n```\n\nConversely, to confirm that _all_ the environment variables\nin a list are set, invoke `Envar.is_set_all?/1`:\n\n```elixir\nif Envar.is_set_all?(~w/ADMIN_EMAIL AUTH_API_KEY/) do\n  # Do something with the required environment variables\nend\n```\n\nWe needed a couple more convenience functions,\nso we wrote them!\n\nIf you need to read an `.env` file and get the\nkeys \u0026 values as a `Map`, invoke `Envar.read/1`:\n\n```elixir\niex\u003e Envar.read(\".env\")\n%{\n  \"ADMIN_EMAIL\" =\u003e \"alex@gmail.com\",\n  \"EVERYTHING\" =\u003e \"awesome!\",\n  \"SECRET\" =\u003e \"master plan\"\n}\n```\n\nIf you need just the `keys`\nof the list of environment variables in an `.env` file,\ninvoke: `Envar.keys/1`:\n\n```elixir\niex\u003e Envar.keys(\".env\")\n[\"ADMIN_EMAIL\", \"EVERYTHING\", \"SECRET\"]\n```\n\nAnd if you need just the `values`\nof the environment variables in an `.env` file,\ninvoke: `Envar.values/1`:\n\n```elixir\niex\u003e Envar.values(\".env\")\n[\"alex@gmail.com\", \"awesome!\", \"master plan\"]\n```\n\nFor more detail, please see docs:\nhttps://hexdocs.pm/envar/Envar.html#functions\n\n\u003cbr /\u003e\u003cbr /\u003e\n\nHappy `Elixir` Coding! 🚀\n\n\u003cbr /\u003e\u003cbr /\u003e\n\n## Context\n\nWe created this module after doing\na search of the `Elixir` (Hex.pm)\necosystem, \u003cbr /\u003e\nsee:\n[dwyl/learn-environment-variables/issues/18](https://github.com/dwyl/learn-environment-variables/issues/18)\n\nThere are several modules available,\nwe wanted something very basic/specific to our needs. \u003cbr /\u003e\nWe don't expect anyone else to use this;\nit's Open Source\nbecause that's just what we do: \u003cbr /\u003e\n[/manifesto.md#open-source-always](https://github.com/dwyl/start-here/blob/master/manifesto.md#open-source-always)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwyl%2Fenvar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwyl%2Fenvar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwyl%2Fenvar/lists"}