Elixir script with dependency

Go the mix project route. Quick and dirty scripts have a way of growing into bigger projects.


Introduced as an experimental feature in Elixir 1.12, Mix.install/2 now allows you to specify a dependency directly in an Elixir script, giving you an alternative to a full-blown mix project.

Usage is quite straightforward: list your dependencies at the top of your script (in the same format that is returned from the regular deps function in a mix project), and it will take care of downloading, compiling, and caching the dependencies for you:

Mix.install([
  {:httpoison, "~> 1.8"},
  :jason
])
HTTPoison.start
IO.puts(Jason.encode!(%{hello: :world}))
...

Tags:

Elixir