Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Add command returns ECONNREFUSED #151

Closed
VoR0220 opened this issue Nov 25, 2015 · 5 comments
Closed

Add command returns ECONNREFUSED #151

VoR0220 opened this issue Nov 25, 2015 · 5 comments
Labels

Comments

@VoR0220
Copy link

VoR0220 commented Nov 25, 2015

Hey guys, trying this out and I can't seem to get this to work, was hoping I could get some answers, currently this is the error I am getting:

{ [Error: Client request error: connect ECONNREFUSED 127.0.0.1:5001]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 5001,
  trace:
   [ { method: 'POST',
       url: 'http://localhost:5001/api/v0/add?stream-channels=true' } ],
  isBoom: true,
  isServer: true,
  data: null,
  output:
   { statusCode: 502,
     payload:
      { statusCode: 502,
        error: 'Bad Gateway',
        message: 'connect ECONNREFUSED 127.0.0.1:5001' },
     headers: {} },
  reformat: [Function]

after creating this module setup:

"use strict";
var fs = require('fs');
var ipfsAPI = require('ipfs-api');
var deasync = require('deasync');

// connect to ipfs daemon API server
var ipfs = ipfsAPI('localhost', '5001', {protocol: 'http'}); // leaving out the arguments will default to these values

module.exports = class IPFS {

    addFile(file) {
        var hash = ipfs.add(file, function(err, res) {
            if(err || !res) return console.error(err)

            res.forEach(function(file) {
                console.log(file.Hash)
                console.log(file.Name)
            });

            return res;
        });
        while(hash === undefined) {
            deasync.runLoopOnce();
        }
    }

    addDir(directory) {
        var files = fs.readdirSync(directory);
        var hashes = ipfs.add(files, function(err, res) {
            if(err || !res) return console.error(err)

            return res;
        });
        while(hashes === undefined) {
            deasync.runLoopOnce();
        }
    }

    getSync(hash, destination_path, recursive) {
        var file;
        if( recursive !== undefined ) {

        }

        file = ipfs.cat(hash, function(err, res) {
            if(err || !res) return console.error(err)

            return fs.writeFile(destination_path, res)
        });

        while(file === undefined) {
            deasync.runLoopOnce();
        }
    }

    addSync(hash, source_path, recursive) {
    }
}

and testing it like this:

var IPFS = require('./ipfs.js'); //the module containing the stuff
var file = './workspace.js';


var ipfs = new IPFS();
console.log('This is IPFS currently: ', ipfs);
ipfs.addFile(file);
console.log('This is after adding a file', ipfs.addFile('./workspace.js'));
@dignifiedquire
Copy link
Contributor

is your is your ipfs daemon running with the correct api port?

@VoR0220
Copy link
Author

VoR0220 commented Nov 25, 2015

do I have to do that for node.js? I was under the assumption that I only need do that for the browser...my mistake if so.

@VoR0220
Copy link
Author

VoR0220 commented Nov 25, 2015

well...that worked.

@VoR0220
Copy link
Author

VoR0220 commented Nov 25, 2015

thanks for the help @dignifiedquire ...and changes to the README oughtta be made...

@VoR0220 VoR0220 closed this as completed Nov 25, 2015
@dignifiedquire
Copy link
Contributor

@VoR0220 yes the readme is not very clear about that, sorry. Yes this repo is only an http base client to interact with an already running ipfs daemon. For the undertaking of doing this all in JavaScript take a look at https://github.com/ipfs/js-ipfs

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants