Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
docs: add docs on running multiple IPFS nodes
Browse files Browse the repository at this point in the history
resolves #1858

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
alanshaw committed Mar 11, 2019
1 parent d2726fb commit 786dbc1
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions examples/running-multiple-nodes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Running multiple JS IPFS nodes

This example takes you through the process needed to run 2 or more JS IPFS nodes on the same computer.

## Via the CLI

Firstly, you'll want to use the `IPFS_PATH` env variable to get a different repo for each instance. Initialise a new IPFS repo like this:

```sh
# IPFS_PATH by default is `~/.jsipfs`.
# The following instructs JS IPFS to use the path `~/.jsipfs2` instead:
IPFS_PATH=~/.jsipfs2 jsipfs init

# Repeat this for as many nodes as you want to run...
```

Secondly, you'll need them to bind to different ports because otherwise bad things happen.

With the CLI, after you've run `ipfs init` you can either edit the config file at `~/.jsipfs/config` (replacing `~/.jsipfs` with the repo path you specified above) or use the config command to update the config e.g. `ipfs config Addresses.API /ip4/0.0.0.0/tcp/4012`. Then start the node with `ipfs daemon`:

```sh
# edit the address ports
vi ~/.jsipfs2/config

# OR

IPFS_PATH=~/.jsipfs2 jsipfs config Addresses.API /ip4/127.0.0.1/tcp/5012

# Repeat this for as many nodes as you want to run...
```

```sh
# ...and then start the daemon
IPFS_PATH=~/.jsipfs2 jsipfs daemon

# Repeat this for as many nodes as you want to run...
```

## Programmatically

Firstly, you'll want to pass the [`repo`](https://github.com/ipfs/js-ipfs#optionsrepo) option to the constructor to get a different repo for each instance:

```js
// The repo path by default is `os.homedir() + '/.jsipfs'`.
new IPFS({ repo: os.homedir() + '/.jsipfs2' })
```

Secondly, you'll need them to bind to different ports because otherwise bad things happen.

To do this, simply pass the different ports to the [`config`](https://github.com/ipfs/js-ipfs#optionsconfig) constructor option. All together:

```js
new IPFS({
repo: os.homedir() + '/.jsipfs2',
config: {
Addresses: {
Swarm: [
'/ip4/0.0.0.0/tcp/4012',
'/ip4/127.0.0.1/tcp/4013/ws'
],
API: '/ip4/127.0.0.1/tcp/5012',
Gateway: '/ip4/127.0.0.1/tcp/9191'
}
}
})
```

0 comments on commit 786dbc1

Please sign in to comment.