0

Here I am making a weather app. First I request and retrieve the data from first three lines and print in the console in the line forth. Since, node.js runs asynchronously the console.log() function runs before the data is retrieve. What should I do??

Code is:

//sending the request
const APIMannager = require("./locationToWeather.js");
const apiMannager = new APIMannager();
const data = apiMannager.getLocation("pokhara");
console.log(data); //prints undefined

//how to run the program one line after another

Abishek
  • 9
  • 3

1 Answers1

0

deasync turns async function into sync, implemented with a blocking mechanism by calling Node.js event loop at JavaScript layer.

Abhishek Jain
  • 826
  • 8
  • 20