I'm facing an issue when trying to retrieve data from a function in node.js. I am somewhat new to node and asynchronous programming, so I probably just overlooked something, but any help is appreciated. Here is the code:
function CallFunc1(col,row){
var GoogleSpreadsheet = require('google-spreadsheet');
var creds = require(Client-Secret Filepath);
var doc = new GoogleSpreadsheet(My Spreadsheet's ID);
doc.useServiceAccountAuth(creds, function (err) {
doc.getCells(1,{'min-row':row,'max-row':row,'min-col':col,'max-col':col}, function (err,resp){
var trv = resp[0];
global.trvf = trv.value
console.log(trvf);
return trvf
});
});
}
console.log(CallFunc1(2,3));
The problem is that when I run it, it returns the value "undefined." It prints the correct result in the console, but when trying to call any data from outside the function it doesn't seem to work.
I apologize if this has already been answered or if it's kinda a noob question.