Connecting to a BEAM node via Elixir script
Start a distributed node with a name and cookie:
$ iex --name server@127.0.0.1 --cookie secret-cookie -S mix phx.server
Create a script:
# add.exs
script_node = :"script@127.0.0.1"
remote_node = :"server@127.0.0.1"
cookie = :"secret-cookie"
{:ok, _pid} = Node.start(script_node)
true = Node.set_cookie(remote_node, cookie)
:pong = Node.ping(remote_node)
true = Node.connect(remote_node)
:rpc.call(remote_node, Enum, :sum, [[1, 2, 3]])
|> inspect()
|> IO.puts()
Run the script:
$ elixir add.exs
6