Sunday, 2 February 2020

How to store a value from a callback function in a global variable??

Hi guys i am trying to store the file.id (from listfiles functon) of a google drive document into the var = "ed" but i get undefined, how i can do it?("return" send me back undefined too)var ed = 'hello' async function Tester(callback) { if (callback) { ed = await callback return; } else { console.log('no value in the callback') } } const listFileS = (auth,q) => { const drive = google.drive({version: 'v3', auth}); console.log(q) drive.files.list({ q: `name contains '${q}' and name contains 'bigliettino' `, pageSize: 1, fields: 'nextPageToken, files(id, name, webContentLink ,webViewLink)', }, (err, res) => { if (err) return console.log('The API returned an error: ' + err); const files = res.data.files; if (files.length) { console.log('Files:'); files.map((file) => { //console.log(`${file.name} (${file.id}) (${file.webContentLink}) (${file.webViewLink})`); return Tester(file.id) }); } else { console.log('No files found.'); } }); } console.log(ed) ​

Submitted February 02, 2020 at 10:47AM by iizMerk

No comments:

Post a Comment