Search code examples
gun

Listen data changes in Gun server


How can I listen the changes occurred in the Gun server database :

My server is listening like below

var Gun = require('gun'); 
var server = http.createServer();
var gun = Gun({web: server});
server.listen(port, function () {
  console.log('Server listening on ...')
})

While puting the data from Gun client my data.json file updated. Now I need to get the listern the whole changes happening in the db. I think on a perticuler node I can listern using gun.on method. Can we able to Listern the whole changes/ change request coming from the client?


Solution

  • @ajmal-m-a yes, via the "wire spec" (you'll need to understand the graph format, here is a tech talk where I explain it in 30min on stage):

    gun.on('in', function(msg){}) where gun is the root.

    Note: You'll need to understand how to handle the middleware event hook system - your listener will need to remember to call this.to.next(msg).

    A good and simple resource to look at is this:

    https://github.com/zrrrzzt/bullet-catcher

    Does this help?

    (Sorry for the delay in answering the question, we were headed into a conference at that time, and it got buried under a bunch of emails)