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

Clone ipfs daemon in node #921

Closed
shortcircuit3 opened this issue Jul 22, 2017 · 11 comments
Closed

Clone ipfs daemon in node #921

shortcircuit3 opened this issue Jul 22, 2017 · 11 comments
Labels
kind/support A question or request for support P3 Low: Not priority right now status/ready Ready to be worked

Comments

@shortcircuit3
Copy link

I'm trying to recreated the command ipfs daemon in node.

const IPFS = require('ipfs')
// Create the IPFS node instance
const node = new IPFS({
  config: { // overload the default config
    API: { // API config for IPFS daemon
      HTTPHeaders: {
        "Access-Control-Allow-Origin": ["*"], // Origins from which to allow http requests
        "Access-Control-Allow-Methods": ["PUT", "GET", "POST"], // "PUT", "GET", "POST", "DELETE", etc.
        "Access-Control-Allow-Credentials": ["true"] // "true" || "false"
      }
    }
  }
})

node.on('ready', () => {

})

But in the browser I''m getting fetch errors

request.js:132 POST http://localhost:5001/api/v0/add?stream-channels=true net::ERR_CONNECTION_REFUSED
@daviddias daviddias added kind/support A question or request for support P3 Low: Not priority right now labels Jul 23, 2017
@daviddias
Copy link
Member

Thanks for reporting this issue @milesalex. You are trying to create a daemon out of the IPFS instance (core). The daemon needs to instantiated differently. See https://github.com/ipfs/js-ipfs#usage

@daviddias daviddias added the status/ready Ready to be worked label Jul 27, 2017
@b0x0tch
Copy link

b0x0tch commented Aug 28, 2017

Were you able to get it to work?

@b0x0tch
Copy link

b0x0tch commented Aug 28, 2017

// Create the IPFS node instance
const node = new IPFS({
  repo: repo,
  init: true,
  start: true,
  config: { // overload the default IPFS node config
    Addresses: {
      Swarm: [
        '/ip4/127.0.0.1/tcp/4001'
      ],
      API: '/ip4/127.0.0.1/tcp/5001'
    }
  }
})

This was my attempt.

@daviddias
Copy link
Member

If you are looking for a daemon in the sense of a running js-ipfs process that exposes an http-api, then check https://github.com/ipfs/js-ipfs/tree/master/src/http-api

If you look to have a instance in the sense of a in process node that does not expose an http-api, but does expose the core api, then check https://github.com/ipfs/js-ipfs#ipfs-core-use-ipfs-as-a-module

@b0x0tch
Copy link

b0x0tch commented Aug 28, 2017

I have my client side run like:

const ipfsAPI = require('ipfs-api')
const ipfs = ipfsAPI('/ip4/127.0.0.1/tcp/5001')

And then trying to expose the core api daemon on port 5001 from the backend:

const IPFS = require('ipfs')
const repo = String(Math.random() + Date.now())


// Create the IPFS node instance
const node = new IPFS({
  repo: repo,
  init: true,
  start: true,
  config: { // overload the default IPFS node config
    Addresses: {
      Swarm: [
        '/ip4/127.0.0.1/tcp/4001'
      ],
      API: '/ip4/127.0.0.1/tcp/5002'
    }
  }
})

I am getting that error from console when i try and connect from the front end:
request.js?af32:132 POST http://127.0.0.1:5001/api/v0/add?recursive=true&stream-channels=true net::ERR_CONNECTION_REFUSED

@b0x0tch
Copy link

b0x0tch commented Aug 28, 2017

Both frontend and backend are running from the same machine! My Goal is to connect to ipfs, without having to run. ipfs daemon locally.

@daviddias
Copy link
Member

@426F746368 you are still trying to run an instance and not a daemon.

You expose a daemon, you need to do this steps https://github.com/ipfs/js-ipfs/blob/master/src/http-api/index.js

@daviddias
Copy link
Member

Another great example is https://github.com/ipfs/js-ipfs/blob/master/test/utils/ipfs-factory-daemon/index.js

@b0x0tch
Copy link

b0x0tch commented Aug 28, 2017

@diasdavid, appreciated. Will def look at them. You reckon it is better to run a daemon on a local machine, yielding better results than on a nodejs server?

@daviddias
Copy link
Member

The daemon is a Node.js server :) Hope this answers your question

MicrowaveDev pushed a commit to galtproject/js-ipfs that referenced this issue May 22, 2020
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
@xinfushe-dev
Copy link

if you want to connect remote server
change the 127.0.0.1 to 0.0.0.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/support A question or request for support P3 Low: Not priority right now status/ready Ready to be worked
Projects
None yet
Development

No branches or pull requests

4 participants