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
{{ message }}
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
The CLI is available by using the command `jsipfs` in your terminal. This is aliased, instead of using `ipfs`, to make sure it does not conflict with the [Go implementation](https://github.com/ipfs/go-ipfs).
157
153
154
+
Once installed, please follow the [Getting Started Guide](https://docs.ipfs.io/introduction/usage/) to learn how to initialize your node and run the daemon.
155
+
158
156
### Use in the browser
159
157
160
158
Learn how to bundle with browserify and webpack in the [`examples`](https://github.com/ipfs/js-ipfs/tree/master/examples) folder.
Creates and returns a ready to use instance of an IPFS node.
251
249
252
-
<details><summary>Alternative method to construct an IPFS node</summary>
253
-
254
-
The recommended method of creating a new IPFS node is to use the `IPFS.create` method. However, IPFS is a `class`, and can also be constructed using the `new` keyword:
255
-
256
-
```js
257
-
constnode=newIPFS([options])
258
-
```
259
-
260
-
At this point, your node has been created but is **not** ready to use. You must either attach a listener for the "ready" event _or_ wait for the `node.ready` promise to resolve:
261
-
262
-
```js
263
-
node.on('ready', () => { /* Node is now ready to use */ })
264
-
// OR
265
-
awaitnode.ready
266
-
```
267
-
</details>
268
-
269
250
Use the `options` argument to specify advanced configuration. It is an object with any of these properties:
270
251
271
252
##### `options.repo`
@@ -585,43 +566,6 @@ You can see the bundle in action in the [custom libp2p example](examples/custom-
585
566
586
567
Configure the libp2p connection manager.
587
568
588
-
#### Events
589
-
590
-
IPFS instances are Node.js [EventEmitters](https://nodejs.org/dist/latest-v8.x/docs/api/events.html#events_class_eventemitter). You can listen for events by calling `node.on('event', handler)`:
- `error` is always accompanied by an `Error` object with information about the error that occurred.
598
-
599
-
```js
600
-
node.on('error', error=> {
601
-
console.error(error.message)
602
-
})
603
-
```
604
-
605
-
- `init` is emitted after a new repo has been initialized. It will not be emitted if you set the `init:false` option on the constructor.
606
-
607
-
- `ready` is emitted when a node is ready to use. This is the final event you will receive when creating a node (after `init` and `start`).
608
-
609
-
When creating a new IPFS node, you should almost always wait for the `ready` event before calling methods or interacting with the node.
610
-
611
-
- `start` is emitted when a node has started listening for connections. It will not be emitted if you set the `start:false` option on the constructor.
612
-
613
-
- `stop` is emitted when a node has closed all connections and released access to its repo. This is usually the result of calling [`node.stop()`](#nodestop).
614
-
615
-
#### `node.ready`
616
-
617
-
A promise that resolves when the node is ready to use. Should be used when constructing an IPFS node using `new`. You don't need to use this if you're using [`awaitIPFS.create`](#ipfs-constructor). e.g.
618
-
619
-
```js
620
-
constnode=newIPFS()
621
-
awaitnode.ready
622
-
// Ready to use!
623
-
```
624
-
625
569
#### `node.start()`
626
570
627
571
Start listening for connections with other IPFS nodes on the network. In most cases, you do not need to call this method — `IPFS.create()` will automatically do it for you.
@@ -640,48 +584,6 @@ try {
640
584
}
641
585
```
642
586
643
-
<details><summary>Starting using callbacks and events</summary>
644
-
645
-
If you pass a function to this method, it will be called when the node is started (Note: this method will **not** return a promise if you use a callback function).
646
-
647
-
```js
648
-
// Note: you can use the class constructor style for more
649
-
// idiomatic callback/events style code
650
-
constnode=newIPFS({ start:false })
651
-
652
-
node.on('ready', () => {
653
-
console.log('Node is ready to use but not started!')
654
-
655
-
node.start(error=> {
656
-
if (error) {
657
-
returnconsole.error('Node failed to start!', error)
658
-
}
659
-
console.log('Node started!')
660
-
})
661
-
})
662
-
```
663
-
664
-
Alternatively you can listen for the [`start` event](#events):
665
-
666
-
```js
667
-
// Note: you can use the class constructor style for more
668
-
// idiomatic callback/events style code
669
-
constnode=newIPFS({ start:false })
670
-
671
-
node.on('ready', () => {
672
-
console.log('Node is ready to use but not started!')
673
-
node.start()
674
-
})
675
-
676
-
node.on('error', error=> {
677
-
console.error('Something went terribly wrong!', error)
Close and stop listening for connections with other IPFS nodes, then release access to the node’s repo.
@@ -700,45 +602,6 @@ try {
700
602
}
701
603
```
702
604
703
-
<details><summary>Stopping using callbacks and events</summary>
704
-
705
-
If you pass a function to this method, it will be called when the node is stopped (Note: this method will **not** return a promise if you use a callback function).
706
-
707
-
```js
708
-
// Note: you can use the class constructor style for more
709
-
// idiomatic callback/events style code
710
-
constnode=newIPFS()
711
-
712
-
node.on('ready', () => {
713
-
console.log('Node is ready to use!')
714
-
715
-
node.stop(error=> {
716
-
if (error) {
717
-
returnconsole.error('Node failed to stop cleanly!', error)
718
-
}
719
-
console.log('Node stopped!')
720
-
})
721
-
})
722
-
```
723
-
724
-
Alternatively you can listen for the [`stop` event](#events).
725
-
726
-
```js
727
-
constnode=newIPFS()
728
-
729
-
node.on('ready', () => {
730
-
console.log('Node is ready to use!')
731
-
node.stop()
732
-
})
733
-
734
-
node.on('error', error=> {
735
-
console.error('Something went terribly wrong!', error)
0 commit comments