Nai
Nai

Reputation: 69

How to create a Elixir node without using IEx?

When using Elixir’s interactive shell IEx, I can create a node by command:

iex --sname node_name

But how can I create a node by code, then run the code by:

elixir code.exs

There are some function like node(), but it seems that those function just return a node existed.

Upvotes: 3

Views: 608

Answers (3)

Ivanhercaz
Ivanhercaz

Reputation: 743

I think what @Nai means is to create a node inside an Elixir application or script. In that case, it is possible to create a node using:

Node.start(:"your_node_name")

Then you can set the cookie with:

Node.set_cookie(:your_security_cookie)

There is a set of useful functions to work with nodes in Elixir in the module Node.

There are some function like node(), but it seems that those function just return a node existed.

About it, node() is a function of the Elixir's kernel (documentation) that returns the node in which you are working and, and if your local node isn't alive, it returns :nonode@nohost. It also can return the node in which a PID, reference or port is running using it node(arg), where arg is the PID, reference or port.

Upvotes: 0

Jason Harrelson
Jason Harrelson

Reputation: 2693

If you are doing an Erlang release you can use the vm.args file. This is how you do it if using exrm to build a release.

Upvotes: 0

Nathaniel Waisbrot
Nathaniel Waisbrot

Reputation: 24473

Use

elixir --sname node_name

Generally, you pass the node name so that everything starts up knowing its own name. However, it is apparently also possible to set the name while running with the Erlang net_kernel module, as described in the answer to How set Erlang node name...

Upvotes: 3

Related Questions