How to add nodes to cluster through source code

I want to add a node to my cluster(currently single node),but i want to add a node through source code.
Which file i should look into.

I don't know what you mean by "through source code". Each node is a separate process, so to add a second node you just configure it and then run it.

Hi @DavidTurner,
i am not running elasticsearch installer,i am running elasticsearch instance by gradlew run in eclipse. How do i add node in this case because elasticsearch.yml gets dynamically generated.

Ah I see. I don't think it's possible to run multiple nodes from an IDE. You can use remote debugging to attach an IDE to a node started elsewhere. It's also possible to write test cases that simulate running multiple nodes: see ESIntegTestCase and its derived classes for examples of this.

In this post , he added nodes by ,
node.max_local_storage_nodes: 4 in elasticsearch.yml .

Is it not possible to hardcode the number of nodes in source code.

Setting node.max_local_storage_nodes doesn't run any extra nodes so I don't think it addresses your question.

There's no way to "hardcode" a setting value, but I don't see why you would want to do that. If you don't want to change it, simply don't change it!