title: Pass data from API to another API nodejs and vanilla Javascript
body: <p>I'm using geonames API and get data from it with a post request. Now I want to take part of these data (lat, long) and pass it through another API (weatherbit API) as my project need to pass (lat and long) in URL and get data from it
  I try to make a get request in server-side to grab information and secure api key but it give me <code>undefined</code>.
  the code gives me <code>undefined</code> in URL parameters</p>
  
  <p>(EX. <a href="https://api.weatherbit.io/v2.0/forecast/daily/&amp;lat=undefined&amp;lon=undefined&amp;key=API_KEY" rel="nofollow noreferrer">https://api.weatherbit.io/v2.0/forecast/daily/&amp;lat=undefined&amp;lon=undefined&amp;key=API_KEY</a>)</p>
  
  <p>here my code
  How can I do this?</p>
  
  <blockquote>
    <p><strong><em>Edit: If I press the button again the request worked fine. So I have to press button 2 times before I get the lat and long data from first API. How to solve this></em></strong></p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/2VLwA.jpg" rel="nofollow noreferrer">first hit on button results</a></p>
  
  <p><a href="https://i.stack.imgur.com/SaWdJ.jpg" rel="nofollow noreferrer">second hit on button results</a></p>
  
  <p><strong>in client-side</strong></p>
  
  <pre><code>const getWeatherIoURL = async (url) =&gt; {
    const response = await fetch(url);
    try {
      const data = await response.text();
      //console.log(data);
      return data;
    } catch (error) {
      console.error(error);
    }
  };
  export default getWeatherIoURL;
  </code></pre>
  
  <p><strong>my code in server-side for both post request and get request</strong></p>
  
  <pre><code>weatherData = {}
  app.post('/geoNamesData', (request, response) =&gt; {
    weatherData['date'] = new Date();
    weatherData['countryName'] = request.body.countryName;
    weatherData['latitude'] = request.body.latitude;
    weatherData['longitude'] = request.body.longitude;
    response.send(weatherData);
  });
  
  //console.log(`your api is: ${process.env.API_WEATHER_KEY}`);
  
  app.get('/weatherURL', (request, respond) =&gt; {
    const url_forecast = 'https://api.weatherbit.io/v2.0/forecast/daily';
    const lat = `lat=${weatherData.latitude}`;
    const long = `lon=${weatherData.longitude}`;
    const url = `${url_forecast}?${lat}&amp;${long}&amp;key=${process.env.API_WEATHER_KEY}`;
    console.log(url);
  
    respond.send(url);
  });
  
  </code></pre>
  
  <p><strong>my code structure</strong></p>
  
  <pre><code>import geoNamesData from './geoNames_data';
  import getWeatherIoURL from './weather_bit';
  import postData from './post_geoNames';
  //import exposeWeatherIoForecast from './weather_bit'
  
  export function main() {
    document.getElementById('search').addEventListener('click', (event) =&gt; {
      event.preventDefault();
      const baseURL = 'http://api.geonames.org/searchJSON?q=';
      const API_Credentials = '&amp;username=*********';
      const destination = document.querySelector('#destination').value;
  
  
      geoNamesData(baseURL, destination, API_Credentials).then((data) =&gt; {
          //console.log(data);
          postData('/geoNamesData', {
            date: new Date(),
            countryName: data.countryName,
            latitude: data.lat,
            longitude: data.lng,
          });
        });
        getWeatherIoURL('/weatherURL').then((data) =&gt; {
          console.log(data);
          exposeWeatherIoForecast(data);
        });
   }
  
  
  </code></pre>
  
  <blockquote>
    <p>the flow of my code is get latitude, longitude and country name for specific city entered by user using geonames API then use the latitude and longitude from this request as a parameters in another API (wathearbit) - which need these data to complete the request - to get the current or forecast weather for the city and update UI with these information ** city, Country Name , weather **</p>
  </blockquote>