Question

I'm working on some distributed code in Elixir, however, I have to keep passing --name to assign a name to my node. Is there anyway to do this by default? I'd like to set something in my .elixirrc file so that each server always has the same node name.

Was it helpful?

Solution

Short answer: no.

Long answer: you can given a name for a node dynamically, so if you find yourself doing many setup tasks (setting cookies, naming nodes, etc), you can have a script that helps you get it started. You will need Elixir v0.10.1 (currently master) for this:

# boot.exs
:net_kernel.start([:foobar, :shortnames])

And then start it:

$ mix run boot.exs

Docs for net_kernel can be found here.

OTHER TIPS

Node.start(:"foobar", :shortnames)

or if you want to use longname

Node.start(:"foobar@172.17.0.1")

Assuming IP address 172.17.0.1. This has to be IP address of machine on which you want to create your node.

You can access this node by simply runningNode.self

I just ran into this too. An easy way to make sure that a node always has a name during development is to add this to .iex.exs:

if Node.self() == :nonode@nohost, do: Node.start(:dev, :shortnames)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top