🎓 A1Learner
🔍
0 of 46 lessons completed

Elixir Node Basics

A node is one running BEAM system with its own name. A plain script starts without a distributed name, so it stands alone.

A node has a name

Node.self() returns the name of the current node. A plain script has no distributed name.

IO.inspect(Node.self())

A plain script is not a live distributed node

Node.alive?() reports whether this node runs with a distributed name. A plain script reports false.

IO.inspect(Node.alive?())

A lone node sees no other nodes

Node.list() returns the nodes this node is linked to. A lone node returns an empty list.

IO.inspect(Node.list())

Example

IO.inspect(Node.self())
IO.inspect(Node.alive?())
IO.inspect(Node.list())
IO.inspect(is_atom(Node.self()))

Key points

  • Node: one running BEAM system with its own name.
  • Node.self(): the name of the current node.
  • Plain script: a script run with elixir file.exs starts without a distributed name.
  • Node.alive?(): true when the node runs with a distributed name, and false otherwise.
  • Node.list(): the list of other nodes this node knows.

In this example, the script prints its own name, then whether it is alive as a distributed node, then its list of other nodes, and finally whether its name is an atom. The four lines together describe a lone node.

Note

the name :nonode@nohost means no distributed name was given.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What does Node.self() return for a plain elixir file.exs script?