brewinstallbuzzwords

brewinstallbuzzwords

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: code — OTP 29.0.2 (kernel 11.0.2)

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?

First 2 of 2 Posts Switch mode

al2o3cr

al2o3cr

There’s not a strong boundary between “Elixir stuff” and “Erlang stuff” - they both ultimately run on the BEAM, and Elixir uses a lot of Erlang functionality with only a thin wrapper on top; for instance, many of the functions in the Elixir Map module mostly exist to make the underlying Erlang functions play nice with |>:

https://github.com/elixir-lang/elixir/blob/33f9d04851a2664aeae5f5f78eeef9e5b4c38030/lib/elixir/lib/map.ex#L236-L237

Historically, it’s been much harder to use Elixir code from Erlang than the other way around, so libraries that need to function in both contexts tend to be written in Erlang. IIRC that is changing nowadays with work being done to bring Hex and rebar closer together.

mpope

mpope

I believe you can use Application.app_dir/2 and point the second argument to the "/priv/..." file you want to access. I don’t think there is anything wrong with using :code.priv_dir/1 directly though.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement