From b8632a3647594d3eb91d3e51400f6b2ef2589f10 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Mon, 6 Jan 2020 13:14:09 +0100 Subject: [PATCH 1/2] docs: improve usage examples add one for createController, improve createFactory --- README.md | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 43cac4d3..4e9e22f6 100644 --- a/README.md +++ b/README.md @@ -34,15 +34,15 @@ npm install --save ipfsd-ctl ## Usage -**Spawn an IPFS daemon from Node.js** +### Spawning a single IPFS daemon: `createController` + +This is a shorthand for simpler use cases where factory is not needed. ```js -// Start a disposable node, and get access to the api -// print the node id, and stop the temporary daemon +// No need to create a factory when only a single node is needed. +// Use createController to spawn it instead. const Ctl = require('ipfsd-ctl') -const factory = Ctl.createFactory() - -const ipfsd = await factory.spawn() +const ipfsd = await Ctl.createController() const id = await ipfsd.api.id() console.log(id) @@ -50,6 +50,28 @@ console.log(id) await ipfsd.stop() ``` +### Spawning multiple IPFS daemons: `createFactory` + +Use a factory to spawn multiple nodes based on some common template. + +**Spawn an IPFS daemon from Node.js** + +```js +// Start two disposable js-ipfs nodes, and get access to apis +// print node ids, and stop temporary daemons +const Ctl = require('ipfsd-ctl') +const factory = Ctl.createFactory({ type: 'js', disposable: true }) + +const ipfsd1 = await factory.spawn() +const ipfsd2 = await factory.spawn() + +console.log(await ipfsd1.api.id()) +console.log(await ipfsd2.api.id()) + +await ipfsd1.stop() +await ipfsd2.stop() +``` + **Spawn an IPFS daemon from the Browser using the provided remote endpoint** ```js @@ -94,7 +116,7 @@ Creates a controller. - `options` **[ControllerOptions](#ControllerOptions)** Factory options. -Returns a **[Controller](#Controller)** +Returns **Promise<[Controller](#controller)>** ### `createServer([options])` 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. From 505114f4f656deadd905ead305a824bd2c33b8a4 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Tue, 7 Jan 2020 01:37:56 +0100 Subject: [PATCH 2/2] docs: example for spawning daemons from Node.js Co-Authored-By: Hugo Dias License: MIT Signed-off-by: Marcin Rataj --- README.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 4e9e22f6..1257920f 100644 --- a/README.md +++ b/README.md @@ -34,12 +34,12 @@ npm install --save ipfsd-ctl ## Usage -### Spawning a single IPFS daemon: `createController` +### Spawning a single IPFS controller: `createController` This is a shorthand for simpler use cases where factory is not needed. ```js -// No need to create a factory when only a single node is needed. +// No need to create a factory when only a single controller is needed. // Use createController to spawn it instead. const Ctl = require('ipfsd-ctl') const ipfsd = await Ctl.createController() @@ -50,26 +50,25 @@ console.log(id) await ipfsd.stop() ``` -### Spawning multiple IPFS daemons: `createFactory` +### Manage multiple IPFS controllers: `createFactory` -Use a factory to spawn multiple nodes based on some common template. +Use a factory to spawn multiple controllers based on some common template. **Spawn an IPFS daemon from Node.js** ```js -// Start two disposable js-ipfs nodes, and get access to apis -// print node ids, and stop temporary daemons +// Create a factory to spawn two test disposable controllers, get access to an IPFS api +// print node ids and clean all the controllers from the factory. const Ctl = require('ipfsd-ctl') -const factory = Ctl.createFactory({ type: 'js', disposable: true }) -const ipfsd1 = await factory.spawn() -const ipfsd2 = await factory.spawn() +const factory = Ctl.createFactory({ type: 'js', test: true, disposable: true }) +const ipfsd1 = await factory.spawn() // Spawns using options from `createFactory` +const ipfsd2 = await factory.spawn({ type: 'go' }) // Spawns using options from `createFactory` but overrides `type` to spawn a `go` controller console.log(await ipfsd1.api.id()) console.log(await ipfsd2.api.id()) -await ipfsd1.stop() -await ipfsd2.stop() +await factory.clean() // Clean all the controllers created by the factory calling `stop` on all of them. ``` **Spawn an IPFS daemon from the Browser using the provided remote endpoint**