You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-53
Original file line number
Diff line number
Diff line change
@@ -40,16 +40,12 @@ npm install --save ipfsd-ctl
40
40
constIPFSFactory=require('ipfsd-ctl')
41
41
constf=IPFSFactory.create()
42
42
43
-
f.spawn(function (err, ipfsd) {
44
-
if (err) { throw err }
43
+
constipfs=awaitf.spawn()
44
+
constid=awaitipfsd.api.id()
45
45
46
-
ipfsd.api.id(function (err, id) {
47
-
if (err) { throw err }
46
+
console.log(id)
48
47
49
-
console.log(id)
50
-
ipfsd.stop()
51
-
})
52
-
})
48
+
awaitipfsd.stop()
53
49
```
54
50
55
51
**Spawn an IPFS daemon from the Browser using the provided remote endpoint**
@@ -64,20 +60,14 @@ const port = 9090
64
60
constserver=IPFSFactory.createServer(port)
65
61
constf=IPFSFactory.create({ remote:true, port: port })
66
62
67
-
server.start((err) => {
68
-
if (err) { throw err }
63
+
awaitserver.start()
64
+
constipfsd=awaitf.spawn()
65
+
constid=awaitipfsd.api.id()
69
66
70
-
f.spawn((err, ipfsd) => {
71
-
if (err) { throw err }
67
+
console.log(id)
72
68
73
-
ipfsd.api.id(function (err, id) {
74
-
if (err) { throw err }
75
-
76
-
console.log(id)
77
-
ipfsd.stop(server.stop)
78
-
})
79
-
})
80
-
})
69
+
awaitipfsd.stop()
70
+
awaitserver.stop()
81
71
```
82
72
83
73
## Disposable vs non Disposable nodes
@@ -112,7 +102,7 @@ Install one or both of the following modules:
112
102
113
103
**example:** See [Usage](#usage)
114
104
115
-
#### Spawn a daemon with `f.spawn([options], callback)`
105
+
#### Spawn a daemon with `f.spawn([options]) : Promise`
116
106
117
107
Spawn the daemon
118
108
@@ -126,14 +116,14 @@ Spawn the daemon
126
116
-`args` - array of cmd line arguments to be passed to ipfs daemon
127
117
-`config` - ipfs configuration options
128
118
129
-
-`callback` - is a function with the signature `function (err, ipfsd)` where:
130
-
-`err` - is the error set if spawning the node is unsuccessful
131
-
-`ipfsd` - is the daemon controller instance:
132
-
-`api` - a property of `ipfsd`, an instance of [ipfs-http-client](https://github.com/ipfs/js-ipfs-http-client) attached to the newly created ipfs node
119
+
Returns a promise that resolves to:
120
+
121
+
-`ipfsd` - is the daemon controller instance:
122
+
-`api` - a property of `ipfsd`, an instance of [ipfs-http-client](https://github.com/ipfs/js-ipfs-http-client) attached to the newly created ipfs node
133
123
134
124
**example:** See [Usage](#usage)
135
125
136
-
#### Get daemon version with `f.version(callback)`
126
+
#### Get daemon version with `f.version() : Promise`
@@ -191,7 +177,7 @@ Get the current repo path. Returns string.
191
177
192
178
Is the node started. Returns a boolean.
193
179
194
-
#### `init([initOpts], callback)`
180
+
#### `init([initOpts]) : Promise`
195
181
196
182
Initialize a repo.
197
183
@@ -200,68 +186,69 @@ Initialize a repo.
200
186
-`directory` (default IPFS_PATH if defined, or ~/.ipfs for go-ipfs and ~/.jsipfs for js-ipfs) - The location of the repo.
201
187
-`pass` (optional) - The passphrase of the key chain.
202
188
203
-
`callback` is a function with the signature `function (err, ipfsd)` where `err` is an Error in case something goes wrong and `ipfsd` is the daemon controller instance.
189
+
Returns a promise that resolves to a daemon controller instance.
204
190
205
-
#### `ipfsd.cleanup(callback)`
191
+
#### `ipfsd.cleanup() : Promise`
206
192
207
193
Delete the repo that was being used. If the node was marked as `disposable` this will be called automatically when the process is exited.
208
194
209
-
`callback` is a function with the signature `function(err)`.
195
+
Returns a promise that resolves when the cleanup is complete.
210
196
211
-
#### `ipfsd.start(flags, callback)`
197
+
#### `ipfsd.start(flags) : Promise`
212
198
213
199
Start the daemon.
214
200
215
201
`flags` - Flags array to be passed to the `ipfs daemon` command.
216
202
217
-
`callback` is a function with the signature `function(err, ipfsClient)` that receives an instance of `Error` on failure or an instance of `ipfs-http-client` on success.
203
+
Returns a promiset hat resolves to an instance of `ipfs-http-client`.
218
204
219
-
220
-
#### `ipfsd.stop([timeout, callback])`
205
+
#### `ipfsd.stop([timeout]) : Promise`
221
206
222
207
Stop the daemon.
223
208
224
-
`callback` is a function with the signature `function(err)` callback - function that receives an instance of `Error` on failure. Use timeout to specify the grace period in ms before hard stopping the daemon. Otherwise, a grace period of `10500` ms will be used for disposable nodes and `10500 * 3` ms for non disposable nodes.
209
+
Use `timeout` to specify the grace period in ms before hard stopping the daemon. Otherwise, a grace period of `10500` ms will be used for disposable nodes and `10500 * 3` ms for non disposable nodes.
210
+
211
+
Returns a promise that resolves when the daemon has stopped.
225
212
226
-
#### `ipfsd.killProcess([timeout, callback])`
213
+
#### `ipfsd.killProcess([timeout]) : Promise`
227
214
228
215
Kill the `ipfs daemon` process. Use timeout to specify the grace period in ms before hard stopping the daemon. Otherwise, a grace period of `10500` ms will be used for disposable nodes and `10500 * 3` ms for non disposable nodes.
229
216
230
217
Note: timeout is ignored for `proc` nodes
231
218
232
219
First a `SIGTERM` is sent, after 10.5 seconds `SIGKILL` is sent if the process hasn't exited yet.
233
220
234
-
`callback` is a function with the signature `function()` called once the process is killed
221
+
Returns a promise that resolves once the process is killed
235
222
236
-
#### `ipfsd.pid(callback)`
223
+
#### `ipfsd.pid() : Promise`
237
224
238
225
Get the pid of the `ipfs daemon` process. Returns the pid number
239
226
240
-
`callback` is a function with the signature `function(err, pid)`that receives the `pid` of the running daemon or an `Error` instance on failure
227
+
Returns a promiset that resolves to the `pid` of the running daemon.
241
228
242
-
#### `ipfsd.getConfig([key], callback)`
229
+
#### `ipfsd.getConfig([key]) : Promise`
243
230
244
231
Returns the output of an `ipfs config` command. If no `key` is passed, the whole config is returned as an object.
245
232
246
233
`key` (optional) - A specific config to retrieve.
247
234
248
-
`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
235
+
Returns a promise that resolves to `Object|string`on success.
249
236
250
-
#### `ipfsd.setConfig(key, value, callback)`
237
+
#### `ipfsd.setConfig(key, value) : Promise`
251
238
252
239
Set a config value.
253
240
254
241
`key` - the key of the config entry to change/set
255
242
256
243
`value` - the config value to change/set
257
244
258
-
`callback` is a function with the signature `function(err)` callback - function that receives an `Error` instance on failure
245
+
Returns a promise that resolves on success.
259
246
260
-
#### `ipfsd.version(callback)`
247
+
#### `ipfsd.version() : Promise`
261
248
262
249
Get the version of ipfs
263
250
264
-
`callback` is a function with the signature `function(err, version)`
0 commit comments