DEV Community

Discussion on: Need help

Collapse
 
saraogipraveen profile image
Praveen Saraogi

Yes, since getWeatherData() is a promise you need to await for it or use then to get data out of it.
For eg:

app.get("/weather", async (req, res) => {
  if (!req.query.location) {
    return res.send({
      error: "You must give an address",
    });
  }
  const data = await getWeatherData(req.query.location);
});
Enter fullscreen mode Exit fullscreen mode

OR

app.get("/weather",  (req, res) => {
  if (!req.query.location) {
    return res.send({
      error: "You must give an address",
    });
  }
  getWeatherData(req.query.location).then(response => {
     const data = response; 
  });
});
Enter fullscreen mode Exit fullscreen mode
Collapse
 
touhidulshawan profile image
Touhidul Shawan

I tried this. But there was slight mistake in my code. Thank you♥️