Reload running modules after code change

I have an small API just using Plugs, no Phoenix. In my local machine will I execute it as “iex -S mix run” if I modify my App.Router to add a new endpoint, then I can go to iex and just do “r App.Router” and new endpoint is available.

My problem is that at the machine I have the app hosted decided to start the app up by doing:
“MIX_ENV=prod elixir --detached --sname foo@localhost -S mix run --no-halt”

Then tried to open another iex console and connect to that node foo@ and it worked but doing the “r Module” or recompile(), any of the added endpoints/changes are loaded.

What is the process to hot reload a running code? read a lot of info but is not working for me. I know some people recommends Destillery but at the moment would like to try it as simply as I do in my local machine.

Keep in mind that this method is not really safe for production. If requests come in while the recompilation process is happening they will get a 500 error. Hot reloading with releases does not have this problem.

1 Like