diff --git a/examples/README.md b/examples/README.md index b7b587eeb5..a4946e37ff 100644 --- a/examples/README.md +++ b/examples/README.md @@ -18,6 +18,7 @@ Let us know if you find any issue or if you want to contribute and add a new tut ## Examples - [js-ipfs in the browser with Browserify](./browser-browserify) +- [js-ipfs in the browser with Parcel.js](./browser-parceljs) - [js-ipfs in the browser with WebPack](./browser-webpack) - [js-ipfs in the browser with a ` + + + + diff --git a/examples/browser-parceljs/public/index.js b/examples/browser-parceljs/public/index.js new file mode 100644 index 0000000000..411b6ea8ad --- /dev/null +++ b/examples/browser-parceljs/public/index.js @@ -0,0 +1,35 @@ +import 'babel-polyfill' +import IPFS from 'ipfs' + +// IPFS node setup +const node = new IPFS({ repo: String(Math.random() + Date.now()) }) + +// UI elements +const status = document.getElementById('status') +const output = document.getElementById('output') + +output.textContent = '' + +function log (txt) { + console.info(txt) + output.textContent += `${txt.trim()}\n` +} + +node.on('ready', async () => { + status.innerText = 'Connected to IPFS :)' + + const version = await node.version() + + log(`The IPFS node version is ${version.version}`) + + const filesAdded = await node.add({ + path: 'hello-parcel.txt', + content: Buffer.from('Hello from parcel.js bundled ipfs example') + }) + + log(`This page deployed ${filesAdded[0].path} to IPFS and its hash is ${filesAdded[0].hash}`) + + const fileBuffer = await node.cat(filesAdded[0].hash) + + log(`The contents of the file was: ${fileBuffer.toString()}`) +})