Skip to content

Instantly share code, notes, and snippets.

@carsonfarmer
Created November 26, 2018 04:57
Show Gist options
  • Save carsonfarmer/6c86be544f85a2376d3221007c1c7ac9 to your computer and use it in GitHub Desktop.
Save carsonfarmer/6c86be544f85a2376d3221007c1c7ac9 to your computer and use it in GitHub Desktop.
Simple module to promisify ipfs initialization
#!/usr/bin/env node
'use strict'
import IPFS from 'ipfs'
const getIpfs = (opts) => {
opts = opts || {}
return new Promise(function (resolve, reject) {
var ipfs = new IPFS(opts)
var onReady = function () {
ipfs.removeListener('error', onError)
resolve(ipfs)
}
var onError = function (err) {
ipfs.removeListener('ready', onReady)
reject(err)
}
ipfs.once('ready', onReady).once('error', onError)
})
}
export default getIpfs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment