Fl4m3Ph03n1x

Fl4m3Ph03n1x

Why do we use application function in mix.exs?

Background

I am trying to understand the purpose of the application function in the mix.exs files we get, but I have some questions that need clarification.

Following is an example of said function:

def application do
    [
      extra_applications: [:logger],
      mod: {FootbalInterface.Application, [http_port: 8080]}
    ]
  end

Questions

  1. Why do we need extra_applications? I understand that in the past we needed to tell mix which applications to run on startup before our app was running. But these days, mix is pretty smart and it starts all needed applications before starting our own app. So why do we still have this value for Elixir 1.9? I think even :logger starts automatically so why do we have it there?

  2. Do we need mod? I understand this tells mix the starting parameters for my app, but if I can simply use Application.get_env in the files, then why do I need this? Will this allow me to start the application by passing values into the command line, like mix -S iex --args http_port: 4000 or something like that?

Marked As Solved

hauleth

hauleth

No unless it will try to send message to the Logger process (so any logging will not work).

Probably yes as any dependency that uses Logger should handle that for you.

Exactly.

Yes, this is done for user convenience. However I think that in future we should move Logger modules to Elixir stdlib and make :logger dummy application as we should move to Erlang’s :logger (which is in :kernel which is always started).

I cannot find any, but I haven’t reviewed it more. Maybe there is option to overwrite such configuration or other stuff. Passing arguments via :mod can also be useful in case of phase usages.

Think about it like CLI options passed in systemd service file vs configuration file for such application.

Also Liked

NobbZ

NobbZ

The return value of the application/0 callback in a Mix.Project is used to build the actual OTP-application manifest.

Whether or not you need :extra_applications and :mod clearly depends on your use case.

:extra_applications is required once you want to embed and start applications into your release that are part of elixir or erlang distribution. If you do not specify them, they won’t get embedded. They are added to the usually infered (since 1.4) :applications key, which you shouldn’t set anymore since inference is in place.

:mod is required if you want an “active” application that has its own supervision tree. It actually tells the runtime how to start and stop the application.

hauleth

hauleth

:logger IIRC starts “automatically” only in development (and in production it will start due to fact that this is commonly present in deps). However there are other applications that can be present in application and aren’t started by default, :inet is one of them (it is automatically started in Phoenix as one of it’s deps include that app).

About :mod it say which is the “launching point” module in our application. Otherwise how would :init supervisor know where is the main launching point of our application? There is no “convention” there.

LostKobrakai

LostKobrakai

There are also a few more keys, which can be present in the returned data of application/0: mix compile.app — Mix v1.20.2

Where Next?

Popular in Questions Top

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement