This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
All new way of initing a node. #790
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e394a85
feat: migrate to new API, check that first test pass, only 300 to go
daviddias 9d56e51
test: moar create node tests
daviddias c76311c
new create node api all tested, now just migrate everywhere
daviddias afccb5e
test: all core tests passing with new api
daviddias 0b97d97
test: every test passes again
daviddias c9232ae
docs: update the readme for init a node
daviddias 050e0f8
docs: update example - basics
daviddias 091fb4e
docs: update remaining examples
daviddias 40b6574
cr
daviddias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,46 +196,54 @@ The HTTP-API exposed by the js-ipfs daemon follows the [`http-api-spec`](https:/ | |
|
||
#### Create a IPFS node instance | ||
|
||
The basic startup flow involves (optionally) creating a Repo, creating an IPFS node, `init`-ing it so it can generate its keys, `load`-ing its configuration, and putting it online with `goOnline`. Here is a structural example: | ||
Creating an IPFS instance couldn't be easier, all you have to do is: | ||
|
||
```JavaScript | ||
// Create the IPFS node instance | ||
const node = new IPFS() | ||
|
||
node.on('start', () => { | ||
// Your now is ready to use \o/ | ||
|
||
// stopping a node | ||
node.stop(() => { | ||
// node is now 'offline' | ||
}) | ||
}) | ||
``` | ||
|
||
#### Advanced options when creating an IPFS node. | ||
|
||
When starting a node, you can: | ||
|
||
```JavaScript | ||
// IPFS will need a repo, it can create one for you or you can pass | ||
// it a repo instance of the type IPFS Repo | ||
// https://github.com/ipfs/js-ipfs-repo | ||
const repo = <IPFS Repo instance or repo path> | ||
|
||
// Create the IPFS node instance | ||
const node = new IPFS({ | ||
repo: repo, | ||
EXPERIMENTAL: { | ||
pubsub: false | ||
init: true, // default | ||
// init: false, | ||
// init: { | ||
// bits: 1024 // size of the RSA key generated | ||
// }, | ||
start: true, | ||
// start: false, | ||
EXPERIMENTAL: { // enable experimental features | ||
pubsub: true | ||
}, | ||
config: { // overload the default config | ||
Addresses: { | ||
Swarm: [ | ||
'/ip4/127.0.0.1/tcp/1337' | ||
] | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No more get/set config madness :) |
||
} | ||
}) | ||
|
||
// We need to init our repo, in this case the repo was empty | ||
// We are picking 2048 bits for the RSA key that will be our PeerId | ||
node.init({ emptyRepo: true, bits: 2048 }, (err) => { | ||
if (err) { throw err } | ||
|
||
// Once the repo is initiated, we have to load it so that the IPFS | ||
// instance has its config values. This is useful when you have | ||
// previous created repos and you don't need to generate a new one | ||
node.load((err) => { | ||
if (err) { throw err } | ||
|
||
// Last but not the least, we want our IPFS node to use its peer | ||
// connections to fetch and serve blocks from. | ||
node.goOnline((err) => { | ||
if (err) { throw err } | ||
// Here you should be good to go and call any IPFS function | ||
}) | ||
}) | ||
``` | ||
|
||
> We are working on making this init process better, see https://github.com/ipfs/js-ipfs/issues/556 for the discussion. | ||
|
||
More examples can be found in the [examples folder](./examples) | ||
|
||
### [Tutorials and Examples](/examples) | ||
|
||
You can find some examples and tutorials in the [examples](/examples) folder, these exist to help you get started using `js-ipfs`. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to make people happier :)