0
저는 Javascript/Node를 처음 접했습니다. 그러나 Python, Java 및 C++에 대한 프로그래밍 만료가 있습니다. 하나. 변수의 범위를 파악할 수없는 것 같습니다. 예를 들어 x라는 변수와 get 메서드를 통해 특정 웹 사이트의 본문을 가져 오는 메서드가 있습니다. 이제 다른 변수에 저장하려고합니다.요청 모듈, Nodejs에서 본체 가져 오기
내 스크립트를
const request = require('request');
var x;
request('http://www.google.com', function(err, res, body) {
return this.x = body;
});
console.log(x); // Should return the "body" from the request method.
반환 :
undefined
[여기] (https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call?rq=1)을 참조하십시오. 코드는 약간 다르지만 개념은 같습니다. – MikaS
해결 했습니까? –