我是NodeJS / java Script的新手。我想知道如何同步调用方法。 例如:
var getData = function (resourceUrl, callback) {
//var done;
// Output representation
var summary = {
title:"",
};
// Request payload
var options = {
uri: MyUrl,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key' : apiKey
},
json: {
"articles": [
{
"type": "article",
"url": resourceUrl,
}
],
}
};
request(options, function (error, response, body) {
summary.title = body.title;
return summary;
}); // end of request function
}); // end of getSummary definition
呼叫者:
var output = getData('www.google.com'); // I need to wait here until getData is done. in C#, we use async/await
console.log(summarizedData);