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);
});
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;
});
});
Yes, since getWeatherData() is a promise you need to
awaitfor it or usethento get data out of it.For eg:
OR
I tried this. But there was slight mistake in my code. Thank you♥️