This repository has been 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.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs/improve newcomers experience (#723)
* docs: update basics example * docs: improve documentation on the readme * docs: update webpack example to have a ref to browserify-zlib-next * docs(examples): update browserify example and add more information about zlib shim * docs(examples): revamp basics example, make it init the repo on tmp * docs(example): fix webpack example
- Loading branch information
Showing
20 changed files
with
229 additions
and
172 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# `js-ipfs` Examples and Tutorials | ||
|
||
In this folder, you can find a variety of examples to help you get started in using js-ipfs, in Node.js and in the Browser. Every example as a specific purpose and some of each incorporate a full tutorial that you can follow through, helping you expand your knowledge about IPFS and the Distributed Web in General. | ||
|
||
Let us know if you find any issue or if you want to contribute and add a new tutorial, feel welcome to submit a PR, thank you! | ||
|
||
## Examples | ||
|
||
- [js-ipfs basic, how to spawn a node and add a file to IPFS](/examples) | ||
- [How to bundle js-ipfs with Browserify](/bundle-browserify) | ||
- [How to bundle js-ipfs with WebPack](/bundle-webpack) | ||
|
||
## Tutorials |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello, how are you today? Welcome to the Distributed Web! |
This file contains 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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
'use strict' | ||
|
||
const fs = require('fs') | ||
const os = require('os') | ||
const series = require('async/series') | ||
const IPFS = require('../../src/core') // replace this by line below | ||
// const IPFS = require('ipfs') | ||
|
||
/* | ||
* Create a new IPFS instance, using default repo (fs) on default path (~/.ipfs) | ||
*/ | ||
const node = new IPFS(os.tmpDir() + '/' + new Date().toString()) | ||
|
||
const fileToAdd = { | ||
path: 'hello.txt', | ||
content: fs.createReadStream('./hello.txt') | ||
} | ||
|
||
let fileMultihash | ||
|
||
series([ | ||
/* | ||
* Display version of js-ipfs | ||
*/ | ||
(cb) => { | ||
node.version((err, version) => { | ||
if (err) { return cb(err) } | ||
|
||
console.log('IPFS Version:', version.version) | ||
cb() | ||
}) | ||
}, | ||
/* | ||
* 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), | ||
/* | ||
* Add a file to IPFS - Complete Files API on: | ||
* https://github.com/ipfs/interface-ipfs-core/tree/master/API/files | ||
*/ | ||
(cb) => { | ||
if (node.isOnline()) { | ||
console.log('\nNode is now ready and online') | ||
} | ||
|
||
node.files.add(fileToAdd, (err, result) => { | ||
if (err) { return cb(err) } | ||
|
||
console.log('\nAdded file:') | ||
console.log(result[0]) | ||
fileMultihash = result[0].hash | ||
cb() | ||
}) | ||
}, | ||
/* | ||
* Awesome we've added a file so let's retrieve and | ||
* display its contents from IPFS | ||
*/ | ||
(cb) => { | ||
node.files.cat(fileMultihash, (err, stream) => { | ||
if (err) { return cb(err) } | ||
|
||
console.log('\nFile content:') | ||
stream.pipe(process.stdout) | ||
stream.on('end', process.exit) | ||
}) | ||
} | ||
], (err) => { | ||
if (err) { | ||
return console.log(err) | ||
} | ||
console.log('Success!') | ||
}) |
This file contains 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 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
File renamed without changes.
3 changes: 2 additions & 1 deletion
3
examples/bundle-browserify/index.js → examples/bundle-browserify/src/index.js
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"stage": 0 | ||
"presets": [ | ||
"stage-0", | ||
"react" | ||
] | ||
} |
This file contains 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
File renamed without changes
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
const React = require('react') | ||
const ReactDOM = require('react-dom') | ||
const App = require('./app') | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')) |
This file was deleted.
Oops, something went wrong.
This file contains 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.