title: How can I fetch all rows in nodejs using promise and function?
body: <p>I created a promise with GetProducts. I'm calling my table named Products from mssql. But &quot;resolve&quot; only returns the first line. How can I return all rows?</p>
  <p>Only when I run the stream all my rows come.
  Best Regards.</p>
  <pre><code>    return new Promise((resolve, reject) =&gt; {
          sql.connect(config, err =&gt; {
              const request = new sql.Request()
              request.stream = true
              request.query('select * from Products')
              request.on('row', row =&gt; {
                  const products = [{ id: row.ProductID, name: row.ProductName}]
                  resolve(products)
              })
          })
          sql.on('error', err =&gt; {
              console.log(err)
          })
      })
  }
  </code></pre>
  <p>Callback;</p>
  <pre><code>
  GetProducts()
      .then((products) =&gt; {
          console.log(products)
      });
  </code></pre>
  <p>Return;</p>
  <pre><code>[ { id: 1, name: 'Chai' } ]
  </code></pre>