I have written google cloud function, which reads file from the bucket and then return the content.
async function getFileContent(fileName, bucketName) {
const storage = new Storage();
const file = await storage.bucket(bucketName).file(fileName);
file.download(function(err, contents) {
console.log("file err: "+err);
console.log("file data: "+contents); //contents is displaying data here
return contents;
});
}
//cloud function starts
exports.getdata = async function(req, res) {
var filecontent = await getFileContent("file1", "bucket1");
console.log("outside "+filecontent); //displaying as undefined
));
}
I want to execute console.log("outside "+filecontent); only once the getFileContent returns value after processing.