gun icon indicating copy to clipboard operation
gun copied to clipboard

Bug? When trying to send from nodejs client

Open fsvieira opened this issue 3 years ago • 2 comments

Hi,

I am new to gun.js I would like to use gun.js outside the browser (nodejs write), and get data from browser (read), reading data from browser works great, but I have a problem writing from node client, I feel that there is a time to setup node client before making a put.

My simple test case is like this:

node : v14.18.1,

Server

  const GUN = require('gun');
  
  const server = require('http').createServer().listen(3030);
  const gun = GUN({web: server});
  
  const t = gun.get('test');
  t.on(data => {
      console.log("Data", data);
  });

Working Client

when I wait a few seconds before making the put and the update is printed on server,

  const GUN = require('./gun');
  
  const gun = GUN('http://localhost:3030/gun');
  const t = gun.get('test');
  
  t.on(data => { en
      console.log(data);
  });
  
  setTimeout(() => 
      t.put({id: 1})
  , 2000);

Not Working Client

I don't wait and make the put, nothing is printed on the server, I also know that is not a problem with .on listener because:

  1. If I restart server, the new records are not printed,
  2. I have made html version to get server updates, and nothing is received, so server just lost the put.
  const GUN = require('./gun');
  
  const gun = GUN('http://localhost:3030/gun');
  const t = gun.get('test');
  
  t.on(data => {
      console.log(data);
  });
  
  t.put({id: 1})

I am not sure if it is a bug because I am new to gun, but I think I have saw some issues that seems similar to this.

I tried to debug it, and I notice that debug this issue makes the print show up on the server, could be the socket connection that needs time to get ready ?

Thanks.

fsvieira avatar Nov 28 '21 01:11 fsvieira

If you haven't already joined chat.gun.eco you may wish to raise this 'issue' with the community. Someone there may get you an answer faster than reporting to this repo.

i001962 avatar Nov 28 '21 22:11 i001962

Hi,

@i001962 thanks for your response, I did raise the question on chat.gun.eco , @amark told me to open the issue.

We also told me to try axe=false flag, but it didn't work, not sure If I did it correctly.

const gun = GUN({peers: ['http://localhost:3030/gun'], axe: false});

fsvieira avatar Nov 29 '21 22:11 fsvieira