0
Talk personal! I have a problem connecting Node.js with Spreedsheet.
I use the function below to fetch the 'date' value in my spreadsheet. Until then it works very well, however, when I use "date" or "data.length" outside the function it returns me: "Promise {} ".
Does anyone know what I should do to be able to use this data out of the accessSpreadsheet function?
async function accessSpreadsheet() {
await promisify (doc.useServiceAccountAuth)(creds);
const info = await promisify(doc.getInfo)();
const sheet = info.worksheets[0];
const data = await promisify(sheet.getRows)({
query: `data = ${datainput}`
});
return data.length;
}
var total = accessSpreadsheet();
console.log(total);
You can use
await
thusvar total = await accessSpreadsheet(
, but the place you call also has to be async. The important thing is to understand how callbacks https://answall.com/q/45706/3635 works and to understand how Promises: https://answall.com/q/119907/3635– Guilherme Nascimento