Skip to content

Commit 7dad936

Browse files
authored
docs: improve usage examples (#421)
1 parent 3e61a00 commit 7dad936

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

README.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,43 @@ npm install --save ipfsd-ctl
3434

3535
## Usage
3636

37-
**Spawn an IPFS daemon from Node.js**
37+
### Spawning a single IPFS controller: `createController`
38+
39+
This is a shorthand for simpler use cases where factory is not needed.
3840

3941
```js
40-
// Start a disposable node, and get access to the api
41-
// print the node id, and stop the temporary daemon
42+
// No need to create a factory when only a single controller is needed.
43+
// Use createController to spawn it instead.
4244
const Ctl = require('ipfsd-ctl')
43-
const factory = Ctl.createFactory()
44-
45-
const ipfsd = await factory.spawn()
45+
const ipfsd = await Ctl.createController()
4646
const id = await ipfsd.api.id()
4747

4848
console.log(id)
4949

5050
await ipfsd.stop()
5151
```
5252

53+
### Manage multiple IPFS controllers: `createFactory`
54+
55+
Use a factory to spawn multiple controllers based on some common template.
56+
57+
**Spawn an IPFS daemon from Node.js**
58+
59+
```js
60+
// Create a factory to spawn two test disposable controllers, get access to an IPFS api
61+
// print node ids and clean all the controllers from the factory.
62+
const Ctl = require('ipfsd-ctl')
63+
64+
const factory = Ctl.createFactory({ type: 'js', test: true, disposable: true })
65+
const ipfsd1 = await factory.spawn() // Spawns using options from `createFactory`
66+
const ipfsd2 = await factory.spawn({ type: 'go' }) // Spawns using options from `createFactory` but overrides `type` to spawn a `go` controller
67+
68+
console.log(await ipfsd1.api.id())
69+
console.log(await ipfsd2.api.id())
70+
71+
await factory.clean() // Clean all the controllers created by the factory calling `stop` on all of them.
72+
```
73+
5374
**Spawn an IPFS daemon from the Browser using the provided remote endpoint**
5475

5576
```js
@@ -94,7 +115,7 @@ Creates a controller.
94115

95116
- `options` **[ControllerOptions](#ControllerOptions)** Factory options.
96117

97-
Returns a **[Controller](#Controller)**
118+
Returns **Promise<[Controller](#controller)>**
98119

99120
### `createServer([options])`
100121
Create an Endpoint Server. This server is used by a client node to control a remote node. Example: Spawning a go-ipfs node from a browser.

0 commit comments

Comments
 (0)