Hi everyone,
I’m working on a small Elixir project that needs to include a text file as a resource. I found on some other posts that this file should exist in the project’s /priv
directory and that I should get the path to priv like this: :code.priv_dir(:my_project)
, and then add the file name to the end using Path.join/2
.
This is working fine, but what’s confusing to me is that this seems to be leveraging Erlang functions.
When I run h :code
in iex I can see that it represents the Erlang code server, which led me to find this page in the Erlang docs: Erlang -- code
There, I was able to find the documentation for priv_dir/1
that I had been struggling to find on hexdocs.
So here’s my question:
Is this the generally accepted way to load a static asset in Elixir? Are there any functions in Elixir that do the same thing, but don’t require making calls to :code
? Are there any other functionalities in Elixir that require making calls to Erlang functionality?