Reading files from your priv dir in elixir
Yesterday i realized my deployed app were throwing errors because it couldn’t find the newly added files it were supposed to read from the priv folder.
Now, Elixir lacks a way to point at the current folder where the app resides but thanks to the compability with erlang we can get it do the job!
By using erlangs Code module (which we reach with the atom
:code) we can get it safely, no matter what environment you’re using.
:code.priv_dir(:my_module_name) iex> "/Users/.../my_module_name/priv"
If you’re unsure what argument to send to
priv_dir, just take a peek in your
mix.exs file and have a look at the value of
def project do [ app: :mintcore, version: "0.1.0", ... ] end