Hwo to use libp2p in browser

Hello.

I have a libp2p node in a backend server. I want to start a libp2p also in the browser that communicates with the one on the backend server.

If I run:

const ma = multiaddr('/ip4/127.0.0.1/tcp/14576/p2p/QmbyBeRur3gUfv7xjxWx8Z3K9UxPXZdnLj9s3SrYKGqwGY')
  //const latency = await node2.ping(ma)

I get error:

The dial request has no valid addresses

Also, thaks to the peer discovery I see that the browser libp2p node is connected to many peers I’d like to have it connected only to my backend libp2p node. How can that be done?

Thanks.

Browsers can’t connect to ip4 nodes, for your use case you would probably want to use a WebSocket. There is also a direct browser to browser tool WebRTC, those are the only two modes available.