Skip to content

Instantly share code, notes, and snippets.

@gerhardberger
Created February 1, 2017 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerhardberger/478c13b27b6acaf5709257cf6838947d to your computer and use it in GitHub Desktop.
Save gerhardberger/478c13b27b6acaf5709257cf6838947d to your computer and use it in GitHub Desktop.
const os = require('os')
const path = require('path')
const IPFS = require('ipfs')
const fileMultihash = process.argv[2]
const node = new IPFS(path.join(os.tmpDir() + '/' + new Date().toString()))
node.version((err, version) => {
if (err) return console.error(err)
console.log('IPFS Version:', version.version)
node.init({ emptyRepo: true, bits: 2048 }, err => {
if (err) return console.error(err)
node.load(err => {
if (err) return console.error(err)
node.goOnline(err => {
if (err) return console.error(err)
console.log('Node is online')
if (node.isOnline()) {
console.log('Node is now ready and online')
node.files.cat(fileMultihash, (err, stream) => {
if (err) return console.error(err)
console.log('File content:')
stream.pipe(process.stdout)
stream.on('end', process.exit)
})
}
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment