diff --git a/README.md b/README.md index 81b9cc8e93..2bc9de8a8a 100644 --- a/README.md +++ b/README.md @@ -196,7 +196,25 @@ 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 @@ -204,38 +222,28 @@ The basic startup flow involves (optionally) creating a Repo, creating an IPFS n // https://github.com/ipfs/js-ipfs-repo const repo = -// 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' + ] + } } }) - -// 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`. diff --git a/examples/basics/index.js b/examples/basics/index.js index 824e4001fc..21fc7929e4 100644 --- a/examples/basics/index.js +++ b/examples/basics/index.js @@ -14,6 +14,8 @@ const IPFS = require('../../src/core') */ const node = new IPFS({ repo: path.join(os.tmpdir() + '/' + new Date().toString()), + init: false, + start: false, EXPERIMENTAL: { pubsub: false } @@ -42,14 +44,10 @@ series([ * Initialize the repo for this node */ (cb) => node.init({ emptyRepo: true, bits: 2048 }, cb), - /* - * Load the repo config into the IPFS node - */ - (cb) => node.load(cb), /* * Take the node online (bitswap, network and so on) */ - (cb) => node.goOnline(cb), + (cb) => node.start(cb), /* * Add a file to IPFS - Complete Files API on: * https://github.com/ipfs/interface-ipfs-core/tree/master/API/files diff --git a/examples/browser-script-tag/index.html b/examples/browser-script-tag/index.html index f51b0d5286..76639158e8 100644 --- a/examples/browser-script-tag/index.html +++ b/examples/browser-script-tag/index.html @@ -4,15 +4,12 @@ IPFS in the Browser