Skip to content

Commit dbe6b37

Browse files
authored
docs: review the readme (#181)
* docs: review the readme * Update README.md * doc: updated `init()` docs
1 parent c60dece commit dbe6b37

File tree

1 file changed

+79
-102
lines changed

1 file changed

+79
-102
lines changed

README.md

+79-102
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[![Appveyor CI](https://ci.appveyor.com/api/projects/status/4p9r12ch0jtthnha?svg=true)](https://ci.appveyor.com/project/wubalubadubdub/js-ipfsd-ctl-a9ywu)
1111
[![Dependency Status](https://david-dm.org/ipfs/js-ipfsd-ctl.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfsd-ctl) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
1212

13-
> Control an ipfs node daemon using either Node.js or the browser
13+
> Control an IPFS daemon using JavaScript in Node.js or in the Browser.
1414
1515
```
1616
+-----+
@@ -51,7 +51,7 @@ npm install --save ipfsd-ctl
5151

5252
IPFS daemons are already easy to start and stop, but this module is here to do it from JavaScript itself.
5353

54-
### Local daemon (_Spawn from from Node.js_)
54+
### Spawn an IPFS daemon from Node.js
5555

5656
```js
5757
// Start a disposable node, and get access to the api
@@ -61,14 +61,18 @@ const DaemonFactory = require('ipfsd-ctl')
6161
const df = DaemonFactory.create()
6262

6363
df.spawn(function (err, ipfsd) {
64+
if (err) { throw err }
65+
6466
ipfsd.api.id(function (err, id) {
67+
if (err) { throw err }
68+
6569
console.log(id)
6670
ipfsd.stop()
6771
})
6872
})
6973
```
7074

71-
### Remote node _(Spawn from a Browser or from a remote machine))
75+
### Spawn an IPFS daemon from the Browser using the provided remote endpoint
7276

7377
```js
7478
// Start a remote disposable node, and get access to the api
@@ -78,18 +82,17 @@ const DaemonFactory = require('ipfsd-ctl')
7882

7983
const port = 9999
8084
const server = DaemonFactory.createServer(port)
81-
const df = DaemonFactory.create({ remote: true, port })
85+
const df = DaemonFactory.create({ remote: true, port: port })
86+
8287
server.start((err) => {
83-
if (err) {
84-
throw err
85-
}
88+
if (err) { throw err }
8689

8790
df.spawn((err, ipfsd) => {
88-
if (err) {
89-
throw err
90-
}
91+
if (err) { throw err }
9192

9293
ipfsd.api.id(function (err, id) {
94+
if (err) { throw err }
95+
9396
console.log(id)
9497
ipfsd.stop(server.stop)
9598
})
@@ -110,174 +113,148 @@ server.start((err) => {
110113

111114
## API
112115

113-
### Daemon Factory
116+
### Daemon Factory Class
114117

115-
#### Create a `DaemonFactory` - `const df = DaemonFactory.create([options])`
118+
#### `DaemonFactory` - `const df = DaemonFactory.create([options])`
116119

117-
> `DaemonFactory.create([options])` returns an object that will expose the `df.spawn` method
120+
`DaemonFactory.create([options])` returns an object that will expose the `df.spawn` method
118121

119122
- `options` - an optional object with the following properties
120123
- `remote` bool - indicates if the factory should spawn local or remote nodes. By default, local nodes are spawned in Node.js and remote nodes are spawned in Browser environments.
121124
- `port` number - the port number to use for the remote factory. It should match the port on which `DaemonFactory.server` was started. Defaults to 9999.
122-
- type - the daemon type to create with this factory. See the section bellow for the supported types
125+
- `type` - the daemon type to create with this factory. See the section bellow for the supported types
126+
- `exec` - path to the desired IPFS executable to spawn, otherwise `ipfsd-ctl` will try to locate the correct one based on the `type`. In the case of `proc` type, exec is required and expects an IPFS coderef.
123127

124-
##### IPFS executable types
125-
126-
`ipfsd-ctl` allows spawning different types of executables, such as:
127-
128-
> `go`
129-
130-
Invoking `df.create({type: 'go'})` will spawn a `go-ipfs` node.
131-
132-
> `js`
133-
134-
Invoking `df.create({type: 'js'})` will spawn a `js-ipfs` node.
135-
136-
> `proc`
137-
138-
Invoking `df.create({type: 'proc'})` will spawn an `in-process-ipfs` node using the provided code reference that implements the core IPFS API. Note that, `exec` option to `df.spawn()` is required if `type: 'proc'` is used.
128+
`ipfsd-ctl` allows spawning different IPFS implementations, such as:
139129

130+
- **`go`** - calling `DaemonFactory.create({type: 'go'})` will spawn a `go-ipfs` daemon.
131+
- **`js`** - calling `DaemonFactory.create({type: 'js'})` will spawn a `js-ipfs` daemon.
132+
- **`proc`** - calling `DaemonFactory.create({type: 'proc', exec: require('ipfs') })` will spawn an `in process js-ipfs node` using the provided code reference that implements the core IPFS API. Note that, `exec` option to `df.spawn()` is required if `type: 'proc'` is used.
140133

134+
#### DaemonFactory endpoint for remote spawning - `const server = DaemonFactory.createServer([options]) `
141135

142-
#### Create a DaemonFactory Endpoint - `const server = DaemonFactory.createServer([options]) `
143-
144-
> `DaemonFactory.createServer` create an instance of the bundled REST API used by the remote controller.
136+
`DaemonFactory.createServer` create an instance of the bundled REST API used by the remote controller.
145137

146-
- exposes `start` and `stop` methods to start and stop the http server.
138+
- exposes `start` and `stop` methods to start and stop the http server endpoint.
147139

148140
#### Spawn a new daemon with `df.spawn`
149141

150-
> Spawn either a js-ipfs or go-ipfs node
142+
Spawn either a js-ipfs or go-ipfs daemon
151143

152-
`spawn([options], callback)`
144+
`df.spawn([options], callback)`
153145

154-
- `options` - is an optional object the following properties
146+
`options` is an optional object the following properties:
155147
- `init` bool (default true) - should the node be initialized
156148
- `start` bool (default true) - should the node be started
157149
- `repoPath` string - the repository path to use for this node, ignored if node is disposable
158150
- `disposable` bool (default false) - a new repo is created and initialized for each invocation, as well as cleaned up automatically once the process exits
159151
- `args` - array of cmd line arguments to be passed to ipfs daemon
160152
- `config` - ipfs configuration options
161-
- `exec` - path to the desired IPFS executable to spawn, otherwise `ipfsd-ctl` will try to locate the correct one based on the `type`. In the case of `proc` type, exec is required and expects an IPFS coderef
162-
163-
- `callback` - is a function with the signature `cb(err, ipfsd)` where:
164-
- `err` - is the error set if spawning the node is unsuccessful
165-
- `ipfsd` - is the daemon controller instance:
166-
- `api` - a property of `ipfsd`, an instance of [ipfs-api](https://github.com/ipfs/js-ipfs-api) attached to the newly created ipfs node
167-
168-
### IPFS Daemon Controller (ipfsd)
169-
170-
> The IPFS daemon controller that allows interacting with the spawned IPFS process
171153

172-
#### `apiAddr` (getter)
154+
`callback` - is a function with the signature `function (err, ipfsd)` where:
155+
- `err` - is the error set if spawning the node is unsuccessful
156+
- `ipfsd` - is the daemon controller instance:
157+
- `api` - a property of `ipfsd`, an instance of [ipfs-api](https://github.com/ipfs/js-ipfs-api) attached to the newly created ipfs node
173158

174-
> Get the address (multiaddr) of connected IPFS API.
159+
### IPFS Daemon Controller (`ipfsd`)
175160

176-
- returns multiaddr
161+
The IPFS daemon controller (`ipfsd`) allows you to interact with the spawned IPFS daemon.
177162

178-
#### `gatewayAddr` (getter)
163+
#### `ipfsd.apiAddr` (getter)
179164

180-
> Get the address (multiaddr) of connected IPFS HTTP Gateway.
165+
Get the address (multiaddr) of connected IPFS API. Returns a multiaddr,
181166

182-
- returns multiaddr
167+
#### `ipfsd.gatewayAddr` (getter)
183168

184-
#### `repoPath` (getter)
169+
Get the address (multiaddr) of connected IPFS HTTP Gateway. Returns a multiaddr.
185170

186-
> Get the current repo path.
171+
#### `ipfsd.repoPath` (getter)
187172

188-
- returns string
173+
Get the current repo path. Returns string
189174

190-
#### `started` (getter)
175+
#### `ipfsd.started` (getter)
191176

192-
> Is the node started.
193-
194-
- returns boolean
177+
Is the node started. Returns a boolean.
195178

196-
#### `init ([initOpts], callback)`
179+
#### `init([initOpts], callback)`
197180

198-
> Initialize a repo.
181+
Initialize a repo.
199182

200-
- `initOpts` (optional) - options object with the following entries
183+
`initOpts` (optional) is an object with the following properties:
201184
- `keysize` (default 2048) - The bit size of the identiy key.
202185
- `directory` (default IPFS_PATH if defined, or ~/.ipfs for go-ipfs and ~/.jsipfs for js-ipfs) - The location of the repo.
203-
- `function (Error, Node)` callback - receives an instance of this Node on success or an instance of `Error` on failure
204-
205-
206-
#### `cleanup (callback)`
207-
208-
> Delete the repo that was being used. If the node was marked as `disposable` this will be called automatically when the process is exited.
186+
187+
`callback` is a function with the signature `function (Error, ipfsd)` where `err` is an Error in case something goes wrong and `ipfsd` is the daemon controller instance.
209188

210-
- `function(Error)` callback
189+
#### `ipfsd.cleanup(callback)`
211190

212-
#### `start (flags, callback)`
191+
Delete the repo that was being used. If the node was marked as `disposable` this will be called automatically when the process is exited.
213192

214-
> Start the daemon.
193+
`callback` is a function with the signature `function(err)`.
215194

216-
- `flags` - Flags array to be passed to the `ipfs daemon` command.
217-
- `function(Error, IpfsApi)}` callback - function that receives an instance of `ipfs-api` on success or an instance of `Error` on failure
195+
#### `ipfsd.start(flags, callback)`
218196

197+
Start the daemon.
219198

220-
#### `stop (callback)`
199+
`flags` - Flags array to be passed to the `ipfs daemon` command.
221200

222-
> Stop the daemon.
201+
`callback` is a function with the signature `function(err, ipfsApi)}` that receives an instance of `ipfs-api` on success or an instance of `Error` on failure
223202

224-
- `function(Error)` callback - function that receives an instance of `Error` on failure
225203

226-
#### `killProcess (callback)`
204+
#### `ipfsd.stop(callback)`
227205

228-
> Kill the `ipfs daemon` process.
206+
Stop the daemon.
229207

230-
First `SIGTERM` is sent, after 10.5 seconds `SIGKILL` is sent if the process hasn't exited yet.
208+
`callback` is a function with the signature `function(err)` callback - function that receives an instance of `Error` on failure
231209

232-
- `function()` callback - Called once the process is killed
210+
#### `ipfsd.killProcess (callback)`
233211

212+
Kill the `ipfs daemon` process.
234213

235-
#### `pid ()`
214+
First a `SIGTERM` is sent, after 10.5 seconds `SIGKILL` is sent if the process hasn't exited yet.
236215

237-
> Get the pid of the `ipfs daemon` process.
216+
`callback` is a function with the signature `function()` called once the process is killed
238217

239-
- returns the pid number
218+
#### `ipfsd.pid ()`
240219

220+
Get the pid of the `ipfs daemon` process. Returns the pid number
241221

242-
#### `getConfig (key, callback)`
222+
#### `ipfsd.getConfig(key, callback)`
243223

244-
> Call `ipfs config`
224+
Returns the output of an `ipfs config` command. If no `key` is passed, the whole config is returned as an object.
245225

246-
If no `key` is passed, the whole config is returned as an object.
226+
`key` (optional) - A specific config to retrieve.
247227

248-
- `key` (optional) - A specific config to retrieve.
249-
- `function(Error, (Object|string)` callback - function that receives an object or string on success or an `Error` instance on failure
228+
`callback` is a function with the signature `function(err, (Object|string)` that receives an object or string on success or an `Error` instance on failure
250229

230+
#### `ipfsd.setConfig (key, value, callback)`
251231

252-
#### `setConfig (key, value, callback)`
232+
Set a config value.
253233

254-
> Set a config value.
234+
`key` - the key of the config entry to change/set
255235

256-
- `key` - the key of the config entry to change/set
257-
- `value` - the config value to change/set
258-
- `function(Error)` callback - function that receives an `Error` instance on failure
236+
`value` - the config value to change/set
259237

238+
`callback` is a function with the signature `function(err)` callback - function that receives an `Error` instance on failure
260239

261-
#### `version (callback)`
240+
#### `ipfsd.version(callback)`
262241

263-
> Get the version of ipfs
242+
Get the version of ipfs
264243

265-
- `function(Error, string)` callback
244+
`callback` is a function with the signature `function(err, version)`
266245

267246
### IPFS Client (`ipfsd.api`)
268247

269-
> An instance of [ipfs-api](https://github.com/ipfs/js-ipfs-api#api)
248+
An instance of [ipfs-api](https://github.com/ipfs/js-ipfs-api#api) that is used to interact with the daemon.
270249

271250
This instance is returned for each successfully started IPFS daemon, when either `df.spawn({start: true})` (the default) is called, or `ipfsd.start()` is invoked in the case of nodes that were spawned with `df.spawn({start: false})`.
272251

273252
### Packaging
274253

275-
`ipfsd-ctl` can be packaged in Electron applications, but the ipfs binary
276-
has to be excluded from asar (Electron Archives),
254+
`ipfsd-ctl` can be packaged in Electron applications, but the ipfs binary has to be excluded from asar (Electron Archives),
277255
[read more about unpack files from asar](https://electron.atom.io/docs/tutorial/application-packaging/#adding-unpacked-files-in-asar-archive).
278-
`ipfsd-ctl` will try to detect if used from within an `app.asar` archive
279-
and tries to resolve ipfs from `app.asar.unpacked`. The ipfs binary is part of
280-
the `go-ipfs-dep` module.
256+
257+
`ipfsd-ctl` will try to detect if used from within an `app.asar` archive and tries to resolve ipfs from `app.asar.unpacked`. The ipfs binary is part of the `go-ipfs-dep` module.
281258

282259
```bash
283260
electron-packager ./ --asar.unpackDir=node_modules/go-ipfs-dep

0 commit comments

Comments
 (0)