Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Elixir script or iex use external modules without creating a new project?

Tags:

elixir

I often write HTTP program with using HTTPoison in Elixir. Of course if I use mix for creating new project and modify mix.exs for dependency for HTTPoison, mix deps.get can resolve dependencies.

However, sometimes I want to try short scripts (.exs) or iex for simple experiment which require external modules without creating a new project.

Are there any methods to solve this requirement like 'libraries search path' in Elixir?

like image 548
HirofumiTamori Avatar asked Aug 23 '15 14:08

HirofumiTamori


1 Answers

The Code module has functions to implement all the things you need. However, it only works with existing files on the machine and you'll need to do pretty much everything "manually".

Code.append_path

Code.ensure_loaded

should accomplish most of what you want.

Another approach is to use iex -S mix in an existing project with the dependencies and then load the .exs file.

like image 57
Fred the Magic Wonder Dog Avatar answered Sep 23 '22 21:09

Fred the Magic Wonder Dog