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

Add command returns ECONNREFUSED #151

Closed
@VoR0220

Description

@VoR0220

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'));

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions