O'Reilly logo

Elixir Cookbook by Paulo A Pereira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Executing code in a different node

It is possible to define a function in a node and execute it in another one.

In this recipe, we will be connecting two nodes and will define a function to print a greeting message with the greeter name (in this case, the node's full name). Afterwards, we will execute the function in both nodes!

Getting ready

To be able to execute a function in another node, we will start by following the steps from the previous recipe. We will create two nodes and connect them together. Repeat the steps from the previous recipe to get started.

How to do it…

With both nodes up and running and connected, we are ready to start:

  1. Define a function in node one:
    iex(one@127.0.0.1)4> greeting_node = fn() -> IO.puts("Hello from #{inspect(Node.self)}") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required