I think I am having a problem understanding the await/promises in Node.js, I thought I was implementing it correctly but it does not look right...
I have this function to get a list of files from my Google Drive:
const listFiles = async () => {
const filesList = await googleDrive.listFiles();
filesList.forEach((file)=>{
console.log(`File is ${file.name}`);
});
return filesList;
}
This function works fine, but now I tried to call it like this in my main.js:
const listFiles = async () => {
const filesList = await googleDrive.listFiles();
filesList.forEach((file)=>{
console.log(`File is ${file.name} with id`);
});
return filesList;
}
const getFiles =() =>{
const files = listFiles();
console.log(files);
};
getFiles();
So my problem here is that, from getFiles()I always get Promise { <pending> } as a console.log...but in my listFiles(), I can see the files being printed correctly after the await....I do not really get it, after the await, the filesList should be ready and resolved.
What am I doing wrong here?