Node 7.3.0 does not support async/await without a feature flag : 디버그에서
let getContent = function (url) {
// return new pending promise
return new Promise((resolve, reject) => {
// select http or https module, depending on reqested url
const lib = url.startsWith('https') ? require('https') : require('http');
const request = lib.get(url, (response) => {
// handle http errors
if (response.statusCode < 200 || response.statusCode > 299) {
reject(new Error('Failed to load page, status code: ' + response.statusCode));
}
// temporary data holder
const body = [];
// on every content chunk, push it to the data array
response.on('data', (chunk) => body.push(chunk));
// we are done, resolve promise with those joined chunks
response.on('end',() => resolve(body.join('')));
});
// handle connection errors of the request
request.on('error', (err) => reject(err))
})
};
let get = async function (url) {
var content = await getContent(url);
return content;
}
var html = get('https://developer.mozilla.org/it/');
내가이 나타납니다. 이 같은 노드를 산란하는 것은 트릭을 수행해야합니다 version 5.5에, V8, 크롬의 자바 스크립트 엔진을 업데이트에서 오는
노드가 이제 공식적으로 async/await by default in version 7.6.0을 지원
node --harmony-async-await app.js
EDIT.
플래그없이 지원 되셨습니까? 내가 볼 수있는 것부터 (http://kangax.github.io/compat-table/es2016plus/), 당신은 당신의 노드를'--harmony' 또는'--es_staging' 플래그로 생성 할 필요가있는 것처럼 보입니다 . –