Changing IPFS configurations and swarm.key programatically

Hi everyone ,
how can we change IPFS swarm-key and default listening port programatically ?

I have a scenario where i need to change the swarm key or default port (5001) programmatically.
The solution which i can think of is to update the swarm.key file with new “key” and update the 'API" listening port to say from 5001 to 9001.

Is there a better way to do it ? Please suggest.

Thanks in advance.

You can change the API port through the ipfs config API (also
accessible over the HTTP API).

To change the swarm key, you need to replace the file manually (or write
a script).

1 Like