title: My promise is being resolved before my second query is able to run inside of a .map function
body: <pre><code>       const getAdditionalInfosPromise = (ProgramID, LeadId) =&gt; {
          return new Promise((resolve, reject) =&gt; {
              connection.query(`SELECT * FROM crm_additionalLeadInfoFields WHERE ProgramID= ${ProgramID};`, (error, response) =&gt; {
                  if (error) reject(console.error(error, 'SQL ERROR IN GETADDITIONALINFOPROMISE'));
                  else {
                      let getAdditionalInfosData = [];
                      const getAdditionalInfos = response;
                      getAdditionalInfos.map((data, i) =&gt; {
  ​
                          let tableNameData;
                          // checking to see what our table name is 
                          if (data.TableName === 'leads') {
                              tableNameData = `WHERE id= ${LeadId};`
                          }
                          else {
                              tableNameData = `Where LeadId = ${LeadId};`
                          }
  ​
                          // Remove any white spaces
  ​
                          const columnName = data.ColumnName.replace(/ +/g, "")
  ​
                          connection.query(`SELECT ${columnName} as pertinentValue 
                          FROM ${data.TableName}
                          ${tableNameData}`, (err, res) =&gt; {
                              if (err) console.error(err, 'MY SQL ERR IN GETADDITIONALINFOSPROMISE');
                              else {
                                  console.log(data);
  
                                  if (data.DisplayName !== 'Dealer Name') {
                                      const pertinentValue = res[0].pertinentValue
  ​
                                      getAdditionalInfosData.push({
                                          'id': `additionalItem${i}`,
                                          'label': data.DisplayName,
                                          'value': `${pertinentValue !== null ? pertinentValue : ''}`,
                                          'class': ''
                                      })
  ​
                                  }
                              }
                          })
  
                      })
  
                      resolve(getAdditionalInfosData)
                  }
              })
  ​
          })
      }
  </code></pre>
  
  <p>Any Idea how to make this asynchronous? I tried using the async npm package but was having issue with getting any type of response back from the <code>async.map(array, function (result,callback) {// Was null here} )</code>. As it is right now it is returning an empty object and then logging my data afterwards Thanks to all who help! :)</p>