In an Elixir project, you can use
Path.expand
to define a file or directory as a relative path from the current file.
For example: Path.expand("../../../lib/file.ex")
but how about finding a path from the root level of the project?
If you'd like to get the project's root directory, use
File.cwd!
source: https://groups.google.com/d/topic/elixir-lang-talk/Ls0eJDdMMW8
(note: I pulled this here only so it's not buried in a dead forum behind Google auth wall & subject to Google data preservation policies)
In case of an umbrella app, you can create a key in your config.exs file :
config :some_app,
project_root: File.cwd!
And then use that value from wherever you want in your project :
project_root = Application.fetch_env!(:some_app, :project_root)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With