I'm learning NodeJS a bit to do some automation scripts, but I'm having a problem that I don't know how to solve.
Using google spreadsheet API and "promisify-node" package, I'm requesting some data from an spreadsheet, and trying to return part of the data to be used on another js file.
file: spreadsheet.js
const getProductsConfiguration = async(auth) =>
{
const sheets = google.sheets('v4');
const getValues = promisify(sheets.spreadsheets.values.get);
await getValues({
auth: auth,
spreadsheetId: utils.getSpreadsheedId(config.spreadsheet.configSpreadsheedUrl),
range: `${config.spreadsheet.configTabName}!A8:C1000`,
})
.then(function (response) {
var productsConfiguration = [];
for(var value in response.values)
{
if(response.values[value].length === 0) continue;
var productConfig = {
"productName": response.values[value][0],
"spreadsheetId": response.values[value][1],
"filterId": response.values[value][2]
};
productsConfiguration.push(productConfig);
}
console.log(productsConfiguration);
return productsConfiguration;
})
.catch(function (error){console.log(error); return false;});
};
app.js:
productsConfig = await spreadsheet.getProductsConfiguration(sheetAuth);
console.log(productsConfig);
this console.log is returning "undefined", but the console.log inside "spreadsheet.js" is returning the correct data.
What can I do to solve? thanks