I have a function where I get the weather for a certain location based on the long and lat of the location, using the imported npm package current-weather-data. I have never worked with promises before as I typically use await and async, but this seems interesting and good to learn... when running this chunk of code below, it doesn't render the page and gives me the error (node:52585) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:52585) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
this is my code:
app.get('/admin-dashboard', (req, res) => {
if (req.session.loggedin) {
const location = {
lat: 43.955540,
lon: -79.480950
}
getWeather(location)
.then(weather => {
console.log(`The temperature here is: ${weather.temperature.value}`)
res.render("admin-dashboard", {
page_title: "admin-dashboard",
FN: req.session.firstname,
LN: req.session.lastname,
weather: ${weather.temperature.value},
});
}).catch(err => console.log(err));
} else {
res.render('login.ejs')
}
})