I'm really struggling with my final project for my first ever coding course. Situation:
I'm able to successfully retrieve data from Geonames API, that looks like this:
Geonames API response: {
lat: '50.08804',
lng: '14.42076',
city: 'Prague',
country: 'Czechia'
}
Now I need to pass the lat, lng values onto the next fuction, getWeatherData:
app.get('/weather', getWeatherData);
async function getWeatherData(req, res) {
try {
const { lat, lng } = req.query; // Extract lat and lng from the request query
console.log(`Following geo data are being passed to Weatherbit: Lat: ${lat}, Lng: ${lng}`);
const result = await getWeatherbitData(lat, lng); // Pass lat and lng to getWeatherbitData
console.log('Weatherbit API response:', result);
res.send(result);
} catch (error) {
console.log('Error in getWeatherData:', error);
res.send(error);
}
}
and I keep getting the error message "error in getWeatherData(lat, lng): ReferenceError: data is not defined" that points to the line
const { lat, lng } = req.query; // Extract lat and lng from the request query
I can't figure out why is this happening, or what other way can I declare these values.
I searched on multiple forums and tried different formats of declaring, adjusting the client-side code, but always getting the same error. I'd greatly appreciate any hints on what might be going wrong. [here] project repository for reference