Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Add a few examples to README.md #534

Closed
wants to merge 8 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ This project is available through [npm](https://www.npmjs.com/). To install:
$ npm install ipfs --save
```

Requires npm@3 and node >= 4, tested on OSX & Linux, expected to work on Windows.

### Use in Node.js

To include this project programmatically:
Expand Down Expand Up @@ -110,8 +112,44 @@ The last published version of the package become [available for download](htt

### Examples

> **Will come soon**
```js
var fs = require('fs')
var IPFS = require('ipfs')
var node = new IPFS()

var fileName = './hello.txt'

// Display version of js-ipfs
node.version(function (err, versionData) {
if (!err) {
console.log(versionData)
// We can initialize the repo, however it only needs to be done once.
node.init(function (err) {
// If the repo has been initialized this will tell us.
if (err) console.log(err)
// Ok let's go online and do some cool stuff
node.goOnline(function () {
// We can test to see if we actually are online if we want to
if (node.isOnline()) console.log('Yep, we are online')
// Now that we are online now. Let's add a file.
var readStream = fs.createReadStream(fileName)
node.files.add(readStream, function (err, data) {
if (!err) {
// Awesome we've added a file so let's retrieve and display its contents from IPFS
node.files.cat(data[0].hash, function (err, stream) {
if (!err) {
stream.pipe(process.stdout, { end: false })
// let's call it a day now and go offline
node.goOffline()
} else { console.log('Oops for some reason there was a problem retrieving your file: ' + err) }
})
} else { console.log('Oops there was a problem: ' + err) }
})
})
})
} else { console.log(err) }
})
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the code style to be consistent with our code base, i.e standard

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback. I will read the standard and apply.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :)

### API

A complete API definition will come, meanwhile, you can learn how to you use js-ipfs throught he standard interface at [![](https://img.shields.io/badge/interface--ipfs--core-API%20Docs-blue.svg)](https://github.com/ipfs/interface-ipfs-core)
Expand Down