'nodejs function returning undefined value

the function bellow returns undefined value, I've tried callback and also returns undefined value. bellow is the function call:

 const result =  getWalletId ()
    console.log(result);

The goal is to return the wallet address in string so it can be used later in the app.

var getWalletId = function(){
        var wallet =''
        var options = {
            "method": "POST",
            "hostname": "rest.cryptoapis.io",
        "path": "/v2/wallet-as-a-service/wallets/620bf50cf7a654000644660b/bitcoin/testnet/addresses",
        "qs": [],
        "headers": {
          "Content-Type": "application/json",
          "X-API-Key": "APIKEY"
        }
      };

  var req = https.request(options, function (res) {
    var chunks = [];
    
    res.on("data", function (chunk) {
      chunks.push(chunk);
    });
  
    res.on("end", function () {
      var body = JSON.parse(Buffer.concat(chunks));

 
    wallet = body.data.item.address
    console.log(wallet);
    callback(wallet)
    });

  });

  req.write(JSON.stringify({
    "context": "",
    "data": {
        "item": {
            "label": "yourLabelStringHere"
        }
    }
}));

  req.end();
  
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source