ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - avdi/dotenv_elixir: A port of dotenv to Elixir
A port of dotenv to Elixir. Contribute to avdi/dotenv_elixir development by creating an account on GitHub.
Visit Site

GitHub - avdi/dotenv_elixir: A port of dotenv to Elixir

GitHub - avdi/dotenv_elixir: A port of dotenv to Elixir

Dotenv for Elixir

Build Module Version Hex Docs Total Download License Last Updated

This is a port of @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).

WARNING: Not compatible with Elixir releases

Elixir has an excellent configuration system and this dotenv implementation has a serious limitation in that it isn't available at compile time. It fits very poorly into a deployment setup using Elixir releases, distillery, or similar.

Configuration management should be built around Elixir's existing configuration system. A good example is Phoenix which generates a project where the production config imports the "secrets" from a file stored outside of version control. Even if you're using this for development, the same approach could be taken.

However, if you are using Heroku, Dokku, or another deployment process that does not use releases, read on!

Quick Start

The 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.

First add :dotenv to your dependencies.

For the latest release:

defp deps do
  [
    {:dotenv, "~> 3.0.0"}
  ]
end

Most likely, if you are deploying in a Heroku-like environment, you'll want to only load the package in a non-production environment:

{:dotenv, "~> 3.0.0", only: [:dev, :test]}

For master:

{:dotenv, github: "avdi/dotenv_elixir"}

Fetch your dependencies with mix deps.get.

Now, when you load your app in a console with iex -S mix, your environment variables will be set automatically.

Using Environment Variables in Configuration

Mix loads configuration before loading any application code. 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:

defmodule App.Application do
  use Application

  def start(_type, _args) do
    unless Mix.env == :prod do
      Dotenv.load
      Mix.Task.run("loadconfig")
    end

    # ... the rest of your application startup
  end
end

Elixir 1.9 and older

If 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:

# Configuration for the OTP application
def application do
  [
    mod: { YourApp, [] },
    applications: app_list(Mix.env)
  ]
end

defp app_list(:dev), do: [:dotenv | app_list]
defp app_list(_), do: app_list
defp app_list, do: [...]

Reloading the .env file

The Dotenv.reload!/0 function will reload the variables defined in the .env file.

More examples of the server API usage can be found in dotenv_app_test.exs.

Serverless API

If 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.

The load!/1 function loads variables into the process environment, and can be passed a path or list of paths to read from.

Alternately, load/1 will return a data structure of the variables read from the .env file:

iex> Dotenv.load
%Dotenv.Env{paths: ["/elixir/dotenv_elixir/.env"],
 values: %{"APP_TEST_VAR" => "HELLO"}}

For further details, see the inline documentation. Usage examples can be found in dotenv_test.exs.

Copyright and License

Copyright (c) 2014 Avdi Grimm

This library is released under the MIT License. See the LICENSE.md file for further details.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory