mazz-seven
Hey,
I’m writing a library, in my library I want to get the root project(the actual project using my library) directory path.
I tried, File.cwd!() but I’m getting the root dir of the library.
Few things to know.
I’m calling File.cwd!() outside a function.
I’m using Mix dependency path to bring my library into the project (for testing purposes).
One more thing.
Using File.cwd!() inside a macro will get me the project path. but I don’t want to use a macro ![]()
Thanks
Mazz
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #ai
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
lucaong
That implies that your call
File.cwd!()is executed at compile time. That explains why you see the dependency directory.In other words:
NobbZ
What is “root project dir”? The source folder? It might not exist in a later phase of the applications life cycle…
Also the
cwdmight be anything. Totally depends on from which foldermixwas called when compiling or from where release was actually started…Under some very rare circumstances you do not even have a CWD.
Please be aware of those culprits, and try to avoid the usage in a compile time environment… Especially as those paths might not exist anymore at runtime…
hauleth
From what you have written I assume that you want to distribute some file with your library/application and then read it in the user runtime. This is why there is
priv/directory and:code.priv_dir/1.mazz-seven
Forgot to write my use case
.
I’m trying to read some Markdown files from the user project for example, read this file /lib/pages/index.md and compile it. But I don’t want the user to write some module to
usea library module. (Don’t know if it’s make sense)@NobbZ root dir for me is where the mix file is.
mat-hek
Compiling non-elixir stuff can be done with custom compilers. To my knowledge, you can safely use
File.cwdfrom there.NobbZ
Don’t read randomly from your users dir. Ask them to explicitely specify where to serach.
mazz-seven
Thanks @mat-hek I will take a look at it.
@NobbZ My solution right now is to read a config key with the value Path.expand(“./”) to get the absolute path.
Is that ok?
NobbZ
That seams to be okay, though I wouldn’t expand, but just rely on the fact that its correctly specified as a relative or absolute path.
Also I do hope, that you do not persist the users files into your modules, this will cause a lot of headache and not changing behaviour on change of the source files…
mazz-seven
If it’s note the absolute path it will point to the relative path of the library.
What do you mean by persist the file into my module?
NobbZ
You said you compile the found file. To what? Do you generate new modules from it? Files? Something else?