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: docs/reference/js/api.md
-289Lines changed: 0 additions & 289 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,295 +49,6 @@ The `js-ipfs` and `js-ipfs-http-client` libraries work in browsers, but each has
49
49
50
50
:::
51
51
52
-
## Install JS-IPFS
53
-
54
-
:::: tabs
55
-
56
-
::: tab ipfs-cli
57
-
58
-
### JS-IPFS module
59
-
60
-
To use the CLI on your machine, globally install the `ipfs` Node.js package:
61
-
62
-
```bash
63
-
npm i --location=global ipfs
64
-
```
65
-
66
-
### Build from source
67
-
68
-
To build from source, clone the [source packages](https://github.com/ipfs/js-ipfs) and follow the build instructions.
69
-
70
-
:::
71
-
72
-
::: tab ipfs-core
73
-
74
-
### IPFS core API
75
-
76
-
To use the IPFS core API, install the `ipfs-core` Node.js package:
77
-
78
-
```bash
79
-
npm i ipfs-core
80
-
```
81
-
82
-
### Build from source
83
-
84
-
To build from source, clone the [source packages](https://github.com/ipfs/js-ipfs) and follow the build instructions.
85
-
86
-
:::
87
-
88
-
::: tab ipfs-http-client
89
-
90
-
### HTTP client module
91
-
92
-
To use the client on your machine, install the `ipfs-http-client` Node.js package:
93
-
94
-
```bash
95
-
npm i ipfs-http-client
96
-
```
97
-
98
-
### Build from source
99
-
100
-
To build from source, clone the [source package](https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-http-client) and follow the build instructions.
101
-
102
-
:::
103
-
104
-
::: tab ipfs-client
105
-
106
-
### HTTP client module
107
-
108
-
To use the client on your machine, install the `ipfs-client` Node.js package:
109
-
110
-
```bash
111
-
npm i ipfs-client
112
-
```
113
-
114
-
### Build from source
115
-
116
-
To build from source, clone the [source package](https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-http-client) and follow the build instructions.
117
-
118
-
:::
119
-
120
-
::::
121
-
122
-
## Spawn a node
123
-
124
-
:::: tabs
125
-
126
-
::: tab ipfs-cli
127
-
128
-
To spawn a node using the CLI, simply start the daemon:
129
-
130
-
```bash
131
-
jsipfs daemon
132
-
```
133
-
134
-
You should see an output similar to:
135
-
136
-
```shell
137
-
Initializing IPFS daemon...
138
-
System version: arm64/darwin
139
-
Node.js version: 16.16.0
140
-
Swarm listening on /ip4/127.0.0.1/tcp/4002/p2p/12D3KooWMZr34r6FArFH36QxyT25BM4HL4u2WF7jQzwNdg91awB6
141
-
Swarm listening on /ip4/10.0.0.25/tcp/4002/p2p/12D3KooWMZr34r6FArFH36QxyT25BM4HL4u2WF7jQzwNdg91awB6
142
-
Swarm listening on /ip4/10.2.0.2/tcp/4002/p2p/12D3KooWMZr34r6FArFH36QxyT25BM4HL4u2WF7jQzwNdg91awB6
143
-
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/12D3KooWMZr34r6FArFH36QxyT25BM4HL4u2WF7jQzwNdg91awB6
144
-
js-ipfs version: 0.15.4
145
-
HTTP API listening on /ip4/127.0.0.1/tcp/5002/http
146
-
gRPC listening on /ip4/127.0.0.1/tcp/5003/ws
147
-
Gateway (read only) listening on /ip4/127.0.0.1/tcp/9090/http
148
-
Web UI available at http://127.0.0.1:5002/webui
149
-
Daemon is ready
150
-
```
151
-
152
-
You should be able to point to the [webpage](http://127.0.0.1:5002/webui):
Create a simple Node.js application to host the logic that will allow you to use the RPC API. You'll also use this Node.js application later on to add and remove files.
168
-
169
-
Start by initiating a new project:
170
-
171
-
```bash
172
-
npm init -y
173
-
```
174
-
175
-
If you have not already installed `ipfs-core`, add the `ipfs-core` module to your project:
176
-
177
-
```bash
178
-
npm i ipfs-core
179
-
```
180
-
181
-
Create an `index.js` file for the application logic:
182
-
183
-
```bash
184
-
touch index.js
185
-
```
186
-
187
-
Now, populate the `index.js` file by initiating an `async` function:
188
-
189
-
```js
190
-
constmain=async () => {
191
-
// "await" logic to spawn a node
192
-
}
193
-
194
-
main()
195
-
```
196
-
197
-
To create an IPFS node, add:
198
-
199
-
```js{1,4}
200
-
import * as IPFS from 'ipfs-core';
201
-
202
-
async function main() {
203
-
const node = await IPFS.create();
204
-
}
205
-
206
-
main();
207
-
```
208
-
209
-
This imports IPFS as a dependency and uses the `create()` function to create a node instance.
210
-
211
-
To spawn the node, run the application:
212
-
213
-
```bash
214
-
node index.js
215
-
```
216
-
217
-
You should see an output similar to:
218
-
219
-
```shell
220
-
Swarm listening on /ip4/127.0.0.1/tcp/4002/p2p/12D3KooWMZr34r6FArFH36QxyT25BM4HL4u2WF7jQzwNdg91awB6
221
-
Swarm listening on /ip4/10.0.0.25/tcp/4002/p2p/12D3KooWMZr34r6FArFH36QxyT25BM4HL4u2WF7jQzwNdg91awB6
222
-
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/12D3KooWMZr34r6FArFH36QxyT25BM4HL4u2WF7jQzwNdg91awB6
223
-
```
224
-
225
-
:::
226
-
227
-
::::
228
-
229
-
## Connect to a node
230
-
231
-
:::: tabs
232
-
233
-
::: tab ipfs-http-client
234
-
235
-
Create a simple Node.js application to host the logic that will connect to the API client. You'll use this Node.js application later on to add and remove files.
236
-
237
-
Start by initiating a new project:
238
-
239
-
```bash
240
-
npm init -y
241
-
```
242
-
243
-
If you have not already installed the client library, add the `ipfs-http-client` module to your project:
244
-
245
-
```bash
246
-
npm i ipfs-http-client
247
-
```
248
-
249
-
Create an `index.js` file for the application logic:
250
-
251
-
```bash
252
-
touch index.js
253
-
```
254
-
255
-
Now, populate the `index.js` file with the following to create an instance of the HTTP API client:
256
-
257
-
```js{1,3}
258
-
import { create } from 'ipfs-http-client'
259
-
260
-
const client = create() // the default API address http://localhost:5001
261
-
```
262
-
263
-
This imports the client library and uses the `create()` function to connect to an IPFS API server.
264
-
265
-
To connect to the API, run the application:
266
-
267
-
```bash
268
-
node index.js
269
-
```
270
-
271
-
You should see an output similar to:
272
-
273
-
```shell
274
-
275
-
```
276
-
277
-
:::
278
-
279
-
::: tab ipfs-client
280
-
281
-
Create a simple Node.js application to use the IPFS client as a backend to connect to IPFS servers.
282
-
283
-
Start by initiating a new project:
284
-
285
-
```bash
286
-
npm init -y
287
-
```
288
-
289
-
If you have not already installed the client library, add the `ipfs-http-client` module to your project:
290
-
291
-
```bash
292
-
npm i ipfs-client
293
-
```
294
-
295
-
Create an `index.js` file for the application logic:
296
-
297
-
```bash
298
-
touch index.js
299
-
```
300
-
301
-
Now, populate the `index.js` file with the following to create an instance of the HTTP API client:
302
-
303
-
```js{1,3-5}
304
-
import { create } from 'ipfs-client'
305
-
306
-
const client = create({
307
-
grpc: '/ipv4/127.0.0.1/tcp/5003/ws',
308
-
http: '/ipv4/127.0.0.1/tcp/5002/http'
309
-
})
310
-
311
-
const id = await client.id()
312
-
```
313
-
314
-
This imports the client library and uses the `create()` function to define the server endpoints.
315
-
316
-
To connect to the endpoints, run the application:
317
-
318
-
```bash
319
-
node index.js
320
-
```
321
-
322
-
You should see an output similar to:
323
-
324
-
```shell
325
-
326
-
```
327
-
328
-
:::
329
-
330
-
331
-
::::
332
-
333
-
## Add a file
334
-
335
-
::: warning Section coming soon
336
-
337
-
As the JS-IPFS implementation goes through changes, adding and removing a file are subject to change. For the time being, please reference the [source packages](https://github.com/ipfs/js-ipfs).
0 commit comments