1

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.