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
### Spawn an IPFS daemon from the Browser using the provided remote endpoint
54
+
**Spawn an IPFS daemon from the Browser using the provided remote endpoint**
76
55
77
56
```js
78
57
// Start a remote disposable node, and get access to the api
79
58
// print the node id, and stop the temporary daemon
80
59
81
-
constDaemonFactory=require('ipfsd-ctl')
60
+
constIPFSFactory=require('ipfsd-ctl')
82
61
83
62
constport=9999
84
-
constserver=DaemonFactory.createServer(port)
85
-
constdf=DaemonFactory.create({ remote:true, port: port })
63
+
constserver=IPFSFactory.createServer(port)
64
+
constf=IPFSFactory.create({ remote:true, port: port })
86
65
87
66
server.start((err) => {
88
67
if (err) { throw err }
89
68
90
-
df.spawn((err, ipfsd) => {
69
+
f.spawn((err, ipfsd) => {
91
70
if (err) { throw err }
92
71
93
72
ipfsd.api.id(function (err, id) {
@@ -102,61 +81,90 @@ server.start((err) => {
102
81
103
82
## Disposable vs non Disposable nodes
104
83
105
-
`ipfsd-ctl` can create two types of node controllers, `disposable` and `non-disposable`. A disposable node will be created on a temporary repo which will be optionally initialized and started (the default), as well cleaned up on process exit. A non-disposable node on the other hand, requires the user to initialize and start the node, as well as stop and cleanup after wards. Additionally, a non-disposable will allow you to pass a custom repo using the `repoPath` option, if the `repoPath` is not defined, it will use the default repo for the node type (`$HOME/.ipfs` or `$HOME/.jsipfs`). The `repoPath` parameter is ignored for disposable nodes, as there is a risk of deleting a live repo.
84
+
`ipfsd-ctl` can spawn `disposable` and `non-disposable` daemons.
106
85
107
-
## IPFS executables
86
+
-`disposable`- Creates on a temporary repo which will be optionally initialized and started (the default), as well cleaned up on process exit. Great for tests.
87
+
-`non-disposable` - Requires the user to initialize and start the node, as well as stop and cleanup after wards. Additionally, a non-disposable will allow you to pass a custom repo using the `repoPath` option, if the `repoPath` is not defined, it will use the default repo for the node type (`$HOME/.ipfs` or `$HOME/.jsipfs`). The `repoPath` parameter is ignored for disposable nodes, as there is a risk of deleting a live repo.
108
88
109
-
`ipfsd-ctl` no longer installs go-ipfs nor js-ipfs dependencies, instead it expects them to be provided by the parent project. In order to be able to use both go and js daemons, please make sure that your project includes these two npm packages as dependencies.
89
+
## Batteries not included. Bring your own IPFS executable.
110
90
111
-
-`ipfs` - the js-ipfs implementation
112
-
-`go-ipfs-dep` - the packaged go-ipfs implementation
91
+
Install one or both of the following modules:
113
92
114
-
## API
93
+
-`ipfs` - `> npm i ipfs` - If you want to spawn js-ipfs nodes and/or daemons.
94
+
-`go-ipfs-dep` - `> npm i go-ipfs-dep` - If you want to spwan go-ipfs daemons.
`DaemonFactory.create([options])` returns an object that will expose the `df.spawn` method
121
-
122
-
-`options` - an optional object with the following properties
123
-
-`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.
124
-
-`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.
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.
127
-
128
-
`ipfsd-ctl` allows spawning different IPFS implementations, such as:
96
+
## API
129
97
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.
133
-
134
-
#### DaemonFactory endpoint for remote spawning - `const server = `DaemonFactory.createServer([options]) `
98
+
### `IPFSFactory` - `const f = IPFSFactory.create([options])`
135
99
136
-
`DaemonFactory.createServer` create an instance of the bundled REST API used by the remote controller.
100
+
`IPFSFactory.create([options])` returns an object that will expose the `df.spawn` method
137
101
138
-
- exposes `start` and `stop` methods to start and stop the http server endpoint.
102
+
-`options` - optional object with:
103
+
-`remote` bool - use remote endpoint to spawn the nodes.
104
+
-`port` number - remote endpoint point. Defaults to 9999.
105
+
-`exec` - IPFS executable path. `ipfsd-ctl` will attempt to locate it by default. If you desire to spawn js-ipfs instances in the same process, pass the ref to the module instead (e.g `exec: require('ipfs')`)
106
+
-`type` - the daemon type, see below the options
107
+
-`go` - spawn go-ipfs daemon
108
+
-`js` - spawn js-ipfs daemon
109
+
-`proc` - spawn in-process js-ipfs instance. Needs to be called also with exec. Example: `DaemonFactory.create({type: 'proc', exec: require('ipfs') })`.
139
110
140
-
#### Spawn a new daemon with `df.spawn`
111
+
**example:** See [Usage](#usage)
141
112
142
-
Spawn either a js-ipfs or go-ipfs daemon
113
+
#### Spawn a daemon with `f.spawn([options], callback)`
143
114
144
-
`df.spawn([options], callback)`
115
+
Spawn the daemon
145
116
146
-
`options` is an optional object the following properties:
117
+
-`options` is an optional object the following properties:
147
118
-`init` bool (default true) - should the node be initialized
148
119
-`start` bool (default true) - should the node be started
149
120
-`repoPath` string - the repository path to use for this node, ignored if node is disposable
150
121
-`disposable` bool (default true) - a new repo is created and initialized for each invocation, as well as cleaned up automatically once the process exits
151
122
-`args` - array of cmd line arguments to be passed to ipfs daemon
152
123
-`config` - ipfs configuration options
153
124
154
-
`callback` - is a function with the signature `function (err, ipfsd)` where:
125
+
-`callback` - is a function with the signature `function (err, ipfsd)` where:
155
126
-`err` - is the error set if spawning the node is unsuccessful
156
127
-`ipfsd` - is the daemon controller instance:
157
128
-`api` - a property of `ipfsd`, an instance of [ipfs-api](https://github.com/ipfs/js-ipfs-api) attached to the newly created ipfs node
158
129
159
-
### IPFS Daemon Controller (`ipfsd`)
130
+
**example:** See [Usage](#usage)
131
+
132
+
#### Get daemon version with `f.version(callback)`
133
+
134
+
Get the version without spawning a daemon
135
+
136
+
-`callback` - is a function with the signature `function(err, version)`, where version might be one of the following:
137
+
- if `type` is 'go' a version string like `ipfs version <version number>`
138
+
- if `type` is 'js' a version string like `js-ipfs version: <version number>`
139
+
- if `type` is 'proc' an object with the following properties:
140
+
- version - the ipfs version
141
+
- repo - the repo version
142
+
- commit - the commit hash for this version
143
+
144
+
### Remote endpoint - `const server = `IPFSFactory.createServer([options]) `
145
+
146
+
`IPFSFactory.createServer` starts a IPFSFactory endpoint.
147
+
148
+
**example:**
149
+
```
150
+
const IPFSFactory = require('ipfsd-ctl')
151
+
152
+
const server = IPFSFactory.createServer({ port: 12345 })
153
+
154
+
server.start((err) => {
155
+
if (err) { throw err }
156
+
157
+
console.log('endpoint is running')
158
+
159
+
server.stop((err) => {
160
+
if (err) { throw err }
161
+
162
+
console.log('endpoint has stopped')
163
+
})
164
+
})
165
+
```
166
+
167
+
### IPFS Daemon Controller - `ipfsd`
160
168
161
169
The IPFS daemon controller (`ipfsd`) allows you to interact with the spawned IPFS daemon.
162
170
@@ -246,13 +254,13 @@ Get the version of ipfs
246
254
247
255
`callback` is a function with the signature `function(err, version)`
248
256
249
-
### IPFS Client (`ipfsd.api`)
257
+
### IPFS HTTP Client - `ipfsd.api`
250
258
251
259
An instance of [ipfs-api](https://github.com/ipfs/js-ipfs-api#api) that is used to interact with the daemon.
252
260
253
-
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})`.
261
+
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})`.
254
262
255
-
###Packaging
263
+
## Packaging
256
264
257
265
`ipfsd-ctl` can be packaged in Electron applications, but the ipfs binary has to be excluded from asar (Electron Archives).
258
266
[read more about unpack files from asar](https://electron.atom.io/docs/tutorial/application-packaging/#adding-unpacked-files-in-asar-archive).
0 commit comments