This is not a duplicate question, this is an attempt to get a very specific detail from the exhaustive explanation at How do I return the response from an asynchronous call? which is not covered.
I don't quite understand the abstruse answers to resolving Promises.
I'm attempting to understand how to unwrap my data from a returned Promise.
console.log(data)
doesn't answer the question. "How do I get my payload?".
Why is is this a bloody secret?
I used node REPL to track my coding. I'm doing everything right except the last step, and I'm punching in the dark here.
someasyncFunction()
.then(data => data);
is supposed to return the "unwrapped" payload right? So why am I getting
$ node gettest.js
Promise { <pending> }
There is a technical piece I am missing and I can't seem to get any help answering that last piece.
const https = require('https');
const datastore = {};
async function getInfo (){
https.get('https://www.gnu.org/software/bash/manual/html_node/Command-Line-Editing.html#Command-Line-Editing', (resp) => {
let data='';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
//console.log(data);
return data;
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}
datastore.info = getInfo().then(function (val){
return val;
});
console.log(datastore.info);