I am trying to use the data from one api in another so i need to use the variable in another function call but it is getting undefined even after i've initialized it globally.
  var latitude,longitude;
    var cityn=req.body.cityname;
    const appid="..."
    var unit="metric"
    
    const url1="https://api.openweathermap.org/geo/1.0/direct?q="+cityn+"&limit=5&appid="+appid
    
    https.get(url1,function(response){
       
        response.on("data",function(da){
            const CityDetails=JSON.parse(da);
            latitude=CityDetails[0].lat;
            longitude=CityDetails[0].lon;
            console.log(latitude) //--> defined
            console.log(longitude) //--> defined 
        })
    
    })
    console.log(latitude) //--> undefined
    console.log(longitude) //--> undefined 
    const url2="https://api.openweathermap.org/data/2.5/weather? lat="+latitude+"&lon="+longitude+"&appid="+appid+"&units="+unit;
I tried initializing it globally and also without using 'var' 'const' but both of the ways are not working.
 
    