0
날씨 앱을 만들고 있습니다. 먼저, 처음 세 줄의 데이터를 요청하여 검색하고 줄에서 콘솔에 인쇄합니다. node.js는 비동기 적으로 실행되므로 데이터가 검색되기 전에 console.log() 함수가 실행됩니다. 어떻게해야합니까 ??노드 js에서 한 줄씩 다른 프로그램을 실행하는 방법
코드는 다음과 같습니다
//sending the request
const APIMannager = require("./locationToWeather.js");
const apiMannager = new APIMannager();
const data = apiMannager.getLocation("pokhara");
console.log(data); //prints undefined
// 프로그램을 다른
'약속'또는 '콜백'을 사용해야합니다. 또는'APIManager'가 옵션을 가지고 있다면'getLocation'을 동 기적으로 호출 할 수 있습니다. –
어떻게 할 수 있습니까? @베드로 – Abishek