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 compatibility 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.
iex> :code.priv_dir(:my_module_name) "/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