I have created a script meant to read data from a google sheet, the function getData() returns a promise of an Array. However, when I access the data afterwards, the value of the data is a promise of a function. Why is this the case?
import dotenv from "dotenv";
import { google } from "googleapis";
import { mainModule } from "process";
dotenv.config();
const spreadsheetID = process.env.spreadsheetID;
if (process.env.NODE_ENV == "production") {
var fs = require("fs");
fs.writeFile("./secrets.json", process.env.SECRET, (err: any) => {
err;
});
}
async function getData() {
const auth = new google.auth.GoogleAuth({
keyFile: "secrets.json",
scopes: "https://www.googleapis.com/auth/spreadsheets",
});
const client = await auth.getClient();
const googleSheets = google.sheets({ version: "v4", auth: client });
var getRows = await googleSheets.spreadsheets.values.get({
auth: auth,
spreadsheetId: spreadsheetID,
range: "Sheet1",
});
console.log(getRows.data.values);
console.log(Array.isArray(getRows.data.values))
return getRows.data.values;
}
const data = getData();
data.then(() => {
console.log(Array.isArray(data);
console.log(data);
var present_list = (data as any).forEach((user: any) => {
if (user[4] == "P") {
present_list.append(user);
}
});
console.log(present_list);
});
console.log("asdasd");