title: NodeJS - Events.js cannot read property forEach of undefined
body: <p>I'm facing an issue since 2 days and i can't figure out how to fix it. I've an error on forEach, so my application runs well and then stops without any explication.</p>
  
  <p>Here is the code where the error happens. </p>
  
  <pre><code>    var easy = setInterval(function(){
          keywords.forEach(function(k) {
              tweetModel.find({keyword: k}).sort({date: -1}).limit(20).exec(function(err, data) {
                  var score = [];
                  var date = [];
                  console.log(data);
                  console.log(err)
                  data.forEach(function (item) {
                      score.push(Math.floor(parseFloat(item.score) * 1000) / 1000);
                      date.push(item.date.getDate()+'/'+parseInt(item.date.getMonth() + 1)+'/'+item.date.getFullYear()+':'+parseInt(item.date.getHours() + 1)+':'+item.date.getMinutes());
  
                      tArrayStats[k] = score;
                      tArrayStats['date'] = date;
                  });
  
              });
  
          });
  
          io.sockets.emit('stats',tArrayStats);
      },3000);
  </code></pre>
  
  <p>The error is thrown here </p>
  
  <pre><code>data.forEach(function (item) 
  </code></pre>
  
  <p>but i can't figure out why ! Thanks for you help.</p>
  
  <p>As asked there is the output of console log data : </p>
  
  <p><a href="https://i.stack.imgur.com/UQz33.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UQz33.png" alt="enter image description here"></a></p>
  
  <p><strong>EDITED working code, thanks to @Ids van der Zee</strong></p>
  
  <pre><code>var easy = setInterval(function(){
      keywords.forEach(function(k) {
  
          tweetModel.find({keyword: k}).sort({date: -1}).limit(20).exec(function(err, data) {
              if (data &amp;&amp; !err)
              {
                  var score = [];
                  var date = [];
                  console.log(data);
                  console.log(err)
  
                  data.forEach(function (item) {
                      score.push(Math.floor(parseFloat(item.score) * 1000) / 1000);
                      date.push(item.date.getDate()+'/'+parseInt(item.date.getMonth() + 1)+'/'+item.date.getFullYear()+':'+parseInt(item.date.getHours() + 1)+':'+item.date.getMinutes());
  
                      tArrayStats[k] = score;
                      tArrayStats['date'] = date;
                  });
              }
  
          });
      });
  
      io.sockets.emit('stats',tArrayStats);
  },3000);
  </code></pre>