@@ -34,22 +34,43 @@ npm install --save ipfsd-ctl
34
34
35
35
## Usage
36
36
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.
38
40
39
41
``` 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.
42
44
const Ctl = require (' ipfsd-ctl' )
43
- const factory = Ctl .createFactory ()
44
-
45
- const ipfsd = await factory .spawn ()
45
+ const ipfsd = await Ctl .createController ()
46
46
const id = await ipfsd .api .id ()
47
47
48
48
console .log (id)
49
49
50
50
await ipfsd .stop ()
51
51
```
52
52
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
+
53
74
** Spawn an IPFS daemon from the Browser using the provided remote endpoint**
54
75
55
76
``` js
@@ -94,7 +115,7 @@ Creates a controller.
94
115
95
116
- ` options ` ** [ ControllerOptions] ( #ControllerOptions ) ** Factory options.
96
117
97
- Returns a ** [ Controller] ( #Controller ) **
118
+ Returns ** Promise & lt ; [ Controller] ( #controller ) > **
98
119
99
120
### ` createServer([options]) `
100
121
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