Initialize iex/node with initial instruction

I’ve been having some trouble with getting multiple distributed nodes initialized. Is it possible to initialize multiple distributed nodes with mix, or to pass an init function to iex?

(I’m trying to avoid having to type .init() in every iex shell)

Hi @jonasbhjulstad. Your application module’s start function is generally the place to put code that you want to run on initialization. Often times you should do this via a child in the supervision tree, but you can also do so directly in the start function body too.

I was able to find some code online regarding slave nodes. All I’m looking for is a was to spawn nodes from one iex-shell as a master

<em>:ok = :net_kernel.monitor_nodes(true)
_ = :os.cmd(‘epmd -daemon’)
{ok, master} = Node.start(:master@localhost, :shortnames)</em> <em>setup_slaves = fn(limit) ->
Enum.each(1..limit, fn(index) ->
:slave.start_link(:localhost, ‘slave_#{index}’)
[node() | Node.list()]
end</em> *# setup_slaves.(5) # call this function to create a cluster of 6 nodes*