I don't understand why my code doesn't work, can someone help me ?
I have a file with all my function (listFunction.mjs) and I want to get an array in testCallApi.mjs, but this didn't work. I got an undefined.
When I do a "console.log(list)", I have a result, but when I want to return this value, that didn't want.
Here is my two files, don't pay attention to the auth, it's for google API.
listFunction.mjs:
export function listGroups(auth) {
const service = google.admin({version: 'directory_v1', auth});
var list = [];
service.groups.list({
customer: 'my_customer',
orderBy: 'email',
maxResults: 10,
sortOrder: 'ASCENDING',
}, (err, res) => {
if (err) return console.error('The API returned an error:', err.message);
const groups = res.data.groups;
groups.forEach((group) => {
list.push(group.email);
});
return list;
});
}
testCallApi.mjs
console.log(listGroups(callAPI()));