title: How To: Pass node.js mongodb result to angularjs?
body: <p>So I have a <em>MongoDB</em> that I query using <em>Node.js</em>.</p>
  
  <p>The data is not being sent out using this function and I dont know what is wrong</p>
  
  <pre><code>var findIco = function(db, callback) {
     var cursor =db.collection('footIco').find();
     cursor.each(function(err, doc) {
       // console.log(err);
        if (doc != null) {
          console.log(doc); &lt;------ DISPLAY THE DATA IN THE CONSOLE
        } else {
           callback();
        }
     });
  }; 
  app.get('/icons', function(req, res){
    //calling the function
    MongoClient.connect(url, function(err, db) {
      if(err) {
        console.log(err);
        return res.status(500).send(err);
     }
  
      findIco(db, function(icons) {
           res.header("Access-Control-Allow-Origin", "*");
     res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type");
    console.log(icons);&lt;--------------- IS UNDEFINED
          res.json(icons);
          db.close();
          return;
      });
    });
  });
  app.listen(8080);
  </code></pre>
  
  <p>What am I doing wrong?</p>