Naming Nodes

So far we haven’t needed to give our node a name—we’ve had only one. If we ask Elixir what the current node is called, it’ll give us a made-up name:

 iex>​ Node.self
 :nonode@nohost

We can set the name of a node when we start it. With iex, use either the --name or --sname option. The former sets a fully qualified name:

 $ ​​iex​​ ​​--name​​ ​​wibble@light-boy.local
 iex(wibble@light-boy.local)> Node.self
 :"wibble@light-boy.local"

The latter sets a short name.

The name that’s returned is an atom—it’s in quotes because it contains characters not allowed in a literal atom.

 $ ​​iex​​ ​​--sname​​ ​​wobble
 iex(wobble@light-boy)> Node.self
 :"wobble@light-boy"

Note that in both cases the iex prompt contains the node’s name along ...

Get Programming Elixir 1.3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.