Monday 8 May 2017

get value of a function inside a function on node.js

I having a hard time figuring out how to get a value using meteor's onCreateUser. I'm using the coinbase API so things get weird when calling functions. I can't figure out how to save a value to the user object. Here's my code

 Accounts.onCreateUser(function(options, user) {

   Meteor.call('createWallet',user._id);
   var Client = require('coinbase').Client;

   var client = new Client({
      'apiKey': 'API_KEY',
      'apiSecret': 'API_SECRET',
   });

   client.getAccounts({}, function(err, accounts) {

       user.wallet= accounts; //error here
   });

   return user;
});

Now, after doing some research I know that I should call the inner function from the outer, something like

function outer() { 
    function inner() {
        //return value o assign it
    }
    inner(); // call it or assign it to a user.wallet
}

however i dont know how to call the funtcion and the way of calling the functions here is really confusing me. Any guidance on how to solve this would be highly appreciated.



via Oscar Or

No comments:

Post a Comment