Tag: 节点.js 8

在NodeJs 8. *如何在http.get上应用Async / Await?

下面的代码从指定的url中asynchronous获取结果,并且在接收到数据后,使用nodejs版本8中的asynchronous/等待(*)(不带callback函数),我想从getData方法中返回parsedvariables。 function getData(v, r) { var path = 'http://some.url.com'; var parsed = ""; http.get({ path: path }, function(res) { var body = ''; res.on('data', function(chunk) { body += chunk; }); res.on('end', function() { parsed = JSON.parse(body); // now I would like to return parsed from this function without making use of callback functions, and make […]