title: Return data from asynchronous function in mssql module
body: <p>I am trying to get data from sql server database (I'm using mssql module to do that : <a href="https://www.npmjs.com/package/mssql" rel="nofollow noreferrer">https://www.npmjs.com/package/mssql</a>) and send it to Redis. 
  So I have created three files : </p>
  
  <ul>
  <li><strong>sql_server.js</strong> contains all the functions related to sql_server (like connection to the database and queries)</li>
  <li><strong>redis.js</strong> has functions like connection and set key/value to redis database (the key is an ID and the value is the result of sql_server query)</li>
  <li><strong>server.js</strong> is the main file that call functions of the sql_server and redis files and act like a controller</li>
  </ul>
  
  <p>I would like to stream the sql_server database and send the result to server.js for each row returned . 
  Then the server.js file will pass the result to redis function that will create the couple key/value. </p>
  
  <p>But I am not very familiar with node.js and I don't know how to return the query result to server.js for each row : </p>
  
  <p>Here is <strong>sql_server.js</strong> function to stream database</p>
  
  <pre><code>      execRequests: function(requestEntry, flux){
      try{            
          const request = new sql.Request(pool)
          request.stream = true // You can set streaming differently for each request 
          request.query(requestEntry)// or request.execute(procedure) 
  
          request.on('recordset', columns =&gt; {
              //console.log(columns); 
          })
  
          request.on('row', row =&gt; {
              // THAT I AM DOING FOR NOW
              //redisMethods.setValue(JSON.stringify(row), flux);
              // THAT I WOULD LIKE TO TO
              //return row;
          })
  
          request.on('error', err =&gt; {
              // May be emitted multiple times 
          })
  
          request.on('done', result =&gt; {
              console.log("done for flux :" + flux);
          })
  
  
  
      } catch (err){
          console.log(err);
      }
  }
  </code></pre>
  
  <p>Here is <strong>server.js</strong></p>
  
  <pre><code>    sqlMethods.connection().then(function(pool){
      try{
          if(pool._connected){
              console.log("Connected to SQL Server database : " + pool.config.database);
              // connection to redis database
              redisMethods.connection();
              // get the requests to execute
              sqlMethods.getRequests().then(function(requestArray){
                  // loop over the array containing requests
                  for (var i in requestArray){
                      let request = requestArray[i].requete; //extract the request
                      let flux = requestArray[i].flux; //extract the flux name
                      sqlMethods.execRequests(request, flux).then(function(result){
                         // redisMethods.setValue(JSON.stringify(result), flux);
                      });
                  }
              });
          }
      } catch (err){
          console.log(err);
      }
  </code></pre>
  
  <p>Hope my explanation is understandable, I need your help to find a way to return the row from sql_server.js to server.js.
  Thank you !</p>