node.jscoinpayments-api

how to parse some data from server response?


I'm new to nodejs. I now have a code like this.

var Coinpayments = require('coinpayments');

var cpayment = new Coinpayments({
  key: 'api',
  secret: 'api',
  autoIpn: true
});

var address = cpayment.getCallbackAddress("BTC", function (err, response) {

console.log(response);
})

which answers the bellow response :

{ address: '3Du1WGxRf1bPZXrX1EyhdAYB4g113RnDeY' }

But I need the answer just like this:

'3Du1WGxRf1bPZXrX1EyhdAYB4g113RnDeY'

can anyone help me?


Solution

  • You'll want to access the value of the address key like this:

    var Coinpayments = require('coinpayments');
    
    var cpayment = new Coinpayments({
      key: 'api',
      secret: 'api',
      autoIpn: true
    });
    
    var address = cpayment.getCallbackAddress("BTC", function (err, response) {
    
    console.log(response.address);
    })