{"id":13507654,"url":"https://github.com/avdi/dotenv_elixir","last_synced_at":"2025-04-12T21:31:15.333Z","repository":{"id":12277702,"uuid":"14900952","full_name":"avdi/dotenv_elixir","owner":"avdi","description":"A port of dotenv to Elixir","archived":false,"fork":false,"pushed_at":"2021-06-10T15:02:33.000Z","size":60,"stargazers_count":232,"open_issues_count":8,"forks_count":27,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T01:09:29.440Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avdi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-03T17:38:38.000Z","updated_at":"2025-03-23T02:56:22.000Z","dependencies_parsed_at":"2022-08-01T08:28:57.845Z","dependency_job_id":null,"html_url":"https://github.com/avdi/dotenv_elixir","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avdi%2Fdotenv_elixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avdi%2Fdotenv_elixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avdi%2Fdotenv_elixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avdi%2Fdotenv_elixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avdi","download_url":"https://codeload.github.com/avdi/dotenv_elixir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248634873,"owners_count":21137138,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-08-01T02:00:37.445Z","updated_at":"2025-04-12T21:31:15.306Z","avatar_url":"https://github.com/avdi.png","language":"Elixir","funding_links":[],"categories":["Configuration"],"sub_categories":[],"readme":"# Dotenv for Elixir\n\n[![Build](https://github.com/avdi/dotenv_elixir/actions/workflows/main.yaml/badge.svg)](https://github.com/avdi/dotenv_elixir/actions/workflows/main.yaml)\n[![Module Version](https://img.shields.io/hexpm/v/dotenv.svg)](https://hex.pm/packages/dotenv)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/dotenv/)\n[![Total Download](https://img.shields.io/hexpm/dt/dotenv.svg)](https://hex.pm/packages/dotenv)\n[![License](https://img.shields.io/hexpm/l/dotenv.svg)](https://github.com/avdi/dotenv_elixir/blob/master/LICENSE.md)\n[![Last Updated](https://img.shields.io/github/last-commit/avdi/dotenv_elixir.svg)](https://github.com/avdi/dotenv_elixir/commits/master)\n\nThis is a port of @bkeepers' [dotenv](https://github.com/bkeepers/dotenv) project to Elixir. You can read more about dotenv on that project's page. The short version is that it simplifies developing projects where configuration is stored in environment variables (e.g. projects intended to be deployed to Heroku).\n\n\u003e WARNING: Not compatible with Elixir releases\n\nElixir has an excellent configuration system and this dotenv implementation\nhas a serious limitation in that it isn't available at compile time. It fits very\npoorly into a deployment setup using Elixir releases, distillery, or similar.\n\nConfiguration management should be built around Elixir's existing configuration\nsystem. A good example is [Phoenix](http://www.phoenixframework.org/) which\ngenerates a project where the production config imports the \"secrets\" from a\nfile stored outside of version control. Even if you're using this for\ndevelopment, the same approach could be taken.\n\nHowever, if you are using Heroku, Dokku, or another deployment process that does *not* use releases, read on!\n\n## Quick Start\n\nThe simplest way to use Dotenv is with the included OTP application. This will automatically load variables from a `.env` file in the root of your project directory into the process environment when started.\n\nFirst add `:dotenv` to your dependencies.\n\nFor the latest release:\n\n```elixir\ndefp deps do\n  [\n    {:dotenv, \"~\u003e 3.0.0\"}\n  ]\nend\n```\n\nMost likely, if you are deploying in a Heroku-like environment, you'll want to only load the package in a non-production environment:\n\n```elixir\n{:dotenv, \"~\u003e 3.0.0\", only: [:dev, :test]}\n```\n\nFor master:\n\n```elixir\n{:dotenv, github: \"avdi/dotenv_elixir\"}\n```\n\nFetch your dependencies with `mix deps.get`.\n\nNow, when you load your app in a console with `iex -S mix`, your environment variables will be set automatically.\n\n## Using Environment Variables in Configuration\n\n[Mix loads configuration before loading any application code.](https://github.com/elixir-lang/elixir/blob/52141f2a3fa69906397017883242948dd93d91b5/lib/mix/lib/mix/tasks/run.ex#L123) If you want to use `.env` variables in your application configuration, you'll need to load dotenv manually on application start and reload your application config:\n\n```elixir\ndefmodule App.Application do\n  use Application\n\n  def start(_type, _args) do\n    unless Mix.env == :prod do\n      Dotenv.load\n      Mix.Task.run(\"loadconfig\")\n    end\n\n    # ... the rest of your application startup\n  end\nend\n```\n\n## Elixir 1.9 and older\n\nIf you are running an old version of Elixir, you'll need to add the `:dotenv` application to your applications list when running in the `:dev` environment:\n\n```elixir\n# Configuration for the OTP application\ndef application do\n  [\n    mod: { YourApp, [] },\n    applications: app_list(Mix.env)\n  ]\nend\n\ndefp app_list(:dev), do: [:dotenv | app_list]\ndefp app_list(_), do: app_list\ndefp app_list, do: [...]\n```\n\n## Reloading the `.env` file\n\nThe `Dotenv.reload!/0` function will reload the variables defined in the `.env` file.\n\nMore examples of the server API usage can be found in [dotenv_app_test.exs](https://github.com/avdi/dotenv_elixir/blob/master/test/dotenv_app_test.exs).\n\n## Serverless API\n\nIf you would like finer-grained control over when variables are loaded, or would like to inspect them, Dotenv also provides a serverless API for interacting with `.env` files.\n\nThe `load!/1` function loads variables into the process environment, and can be passed a path or list of paths to read from.\n\nAlternately, `load/1` will return a data structure of the variables read from the `.env` file:\n\n```elixir\niex\u003e Dotenv.load\n%Dotenv.Env{paths: [\"/elixir/dotenv_elixir/.env\"],\n values: %{\"APP_TEST_VAR\" =\u003e \"HELLO\"}}\n```\nFor further details, see the inline documentation. Usage examples can be found in [dotenv_test.exs](https://github.com/avdi/dotenv_elixir/blob/master/test/dotenv_test.exs).\n\n## Copyright and License\n\nCopyright (c) 2014 Avdi Grimm\n\nThis library is released under the MIT License. See the [LICENSE.md](./LICENSE.md) file\nfor further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favdi%2Fdotenv_elixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favdi%2Fdotenv_elixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favdi%2Fdotenv_elixir/lists"}