title: Nested async queries
body: <pre><code>//express is the framework we're going to use to handle requests
  const express = require('express');
  //Create a new instance of express
  const app = express();
  const FormData = require("form-data");
  const bodyParser = require("body-parser");
  const http = require('http');
  const async = require('async');
  
  //This allows parsing of the body of POST requests, that are encoded in JSON
  app.use(bodyParser.json());
  var router = express.Router();
  
  //AccuWeather API key
  const weatherKey = process.env.WEATHER_KEY_TWO;
  
  
  cityCode = ""; //City code
  cityName = "";
  
  //Current Conditions Vars
  var ccWeatherText = ""; //Text for weather at location
  var ccTemp = 0; //Degrees Farenheit
  var ccIcon = 0; //weather icon number https://developer.accuweather.com/weather-icons
  var ccURL = "test"; //URL for get
  var hourlyData = [];
  var fiveDayData = [];
  
  router.post('/', (req, res) =&gt; {
      let lat = req.body['lat'];
      let lon = req.body['lon'];
      var latLongCityCodeURL = ("http://dataservice.accuweather.com/locations/v1/cities/geoposition/search?apikey=" + weatherKey + "&amp;q=" + lat + "," + lon);
      //Get city code
      const httpGet = url =&gt; {
          return new Promise((resolve, reject) =&gt; {
              http.get(url, res =&gt; {
                  let body = '';
                  res.on('data', chunk =&gt; body += chunk);
                  res.on('end', () =&gt; {
                      try {
                          body = JSON.parse(body);
                      } catch (err) {
                          reject(new Error(err));
                      }
                      resolve({
                          code: body.Key,
                          name: body.EnglishName
                      });
                  });
              }).on('error', reject);
          });
      };
  
      //Current Conditions
      const ccGet = url =&gt; {
          return new Promise((resolve, reject) =&gt; {
              http.get(url, res =&gt; {
                  let body = '';
                  res.on('data', chunk =&gt; body += chunk);
                  res.on('end', () =&gt; {
                      try {
                          body = JSON.parse(body);
                      } catch (err) {
                          reject(new Error(err));
                      }
                      resolve({
                          text: body[0].WeatherText,
                          temp: body[0].Temperature.Imperial.Value,
                          icon: body[0].WeatherIcon
                      });
                  });
              }).on('error', reject);
          });
      };
  
      //12 hour
      const twelveGet = url =&gt; {
          return new Promise((resolve, reject) =&gt; {
              http.get(url, res =&gt; {
                  let body = '';
                  res.on('data', chunk =&gt; body += chunk);
                  res.on('end', () =&gt; {
                      try {
                          body = JSON.parse(body);
                      } catch (err) {
                          reject(new Error(err));
                      }
                      resolve({
                          body: body
                      });
                  });
              }).on('error', reject);
          });
      };
  
      //5 day
      const fiveGet = url =&gt; {
          return new Promise((resolve, reject) =&gt; {
              http.get(url, res =&gt; {
                  let body = '';
                  res.on('data', chunk =&gt; body += chunk);
                  res.on('end', () =&gt; {
                      try {
                          body = JSON.parse(body);
                      } catch (err) {
                          reject(new Error(err));
                      }
                      resolve({
                          body: body
                      });
                  });
              }).on('error', reject);
          });
      };
  
      //Get city code from lat lon
      httpGet(latLongCityCodeURL).then(data =&gt; {
          cityCode = data.code;
          cityName = data.name;
          ccURL = ("http://dataservice.accuweather.com/currentconditions/v1/" + cityCode + "?apikey=" + weatherKey);
          twelveURL = ("http://dataservice.accuweather.com/forecasts/v1/hourly/12hour/" + cityCode + "?apikey=" + weatherKey);
          fiveURL = ("http://dataservice.accuweather.com/forecasts/v1/daily/5day/" + cityCode + "?apikey=" + weatherKey);
          //Get Current Conditions
          ccGet(ccURL).then(dataCC =&gt; {
              ccTemp = dataCC.temp;
              ccWeatherText = dataCC.text;
              ccIcon = dataCC.icon;
              //Get 12 hour forecast
              twelveGet(twelveURL).then(dataTwelve =&gt; {
                  //Generate hourly data
                  for (i = 0; i &lt; dataTwelve.length; i++) {
                      hourlyData[i] = {
                          time: dataTwelve[i].EpochDateTime,
                          temp: dataTwelve[i].Temperature.Value,
                          text: dataTwelve[i].IconPhrase,
                          icon: dataTwelve[i].WeatherIcon
                      };
                  }
                  console.log("Hourly Data: " + hourlyData);
              }).catch(err =&gt; console.log(err));
              fiveGet(fiveURL).then(dataFive =&gt; {
                  //Generate five day data
                  for (i = 0; i &lt; dataFive.length; i++) {
                      fiveDayData[i] = {
                          time: dataFive[i].EpochDate,
                          min: dataFive[i].Temperature.Minimum.Value,
                          max: dataFive[i].Temperature.Maximum.Value,
                          iconDay: dataFive[i].Day.Icon,
                          iconNight: dataFive[i].Night.Icon,
                          dayPhrase: dataFive[i].Day.IconPhrase,
                          nightPhrase: dataFive[i].Night.IconPhrase
                      };
                      console.log("5 Day Data:" + fiveDayData);
                  }
                  res.send({
                      success: true,
                      cityName: cityName,
                      cityCode: cityCode,
                      currentConditions: {
                          temp: ccTemp,
                          icon: ccIcon,
                          text: ccWeatherText
                      },
                      hourlyData: hourlyData,
                      fiveDayData: fiveDayData
                  });
              }).catch(err =&gt; console.log(err));
          }).catch(err =&gt; console.log(err));
      }).catch(err =&gt; console.log('Got error ', err));
  });
  
  
  module.exports = router;
  </code></pre>
  
  <p>Ok so right now I'm creating an endpoint in NodeJS that is  POST method which gets the arguments for latitude and longitude. When it gets those it makes calls to Accuweather's API. I got all the accuweather stuff working and returning proper results, but then I cut and pasted that code into my POST method <code>router.post...</code> and now it isn't working. I know it is an ASYNC issue, and I am just getting really lost with async, since I have like 3 or 4 nested async calls inside the router.post, which is another async call. So I'm thinking there is some way to maybe wrap the <code>router.post</code> into its own async call, which waits on the weather calls before returning results?<p>
  My end goal: For the user to send a POST with lat and lon, my code does all the weather calls, and returns the data for the POST.</p>