title: node.js: expressjs with mongoose
body: <p>I'm working on my first node.js / express / mongoose app and I'm facing a problem due to asynchronisation mechanism of node.js. It seems I do not do the thing correctly...</p>
  
  <p>Here is the test route I defined using express:</p>
  
  <pre><code>app.get('/test', function(req, res){
    var mod = mongoose.model('MyModel');
    mod.find({},function(err, records){
      records.forEach(function(record){
        console.log('Record found:' + record.id);
        // res.send('Thing retrieved:' + record.id);
      });
    });
  });
  </code></pre>
  
  <p>When I issue a <a href="http://localhost/test" rel="noreferrer">http://localhost/test</a>, I'd like to get the list of records of type 'MyModel' in the response.</p>
  
  <p>The code above is working fine but when it comes to returning this whole list to the client... it does not work (the commented res.send line) and only returned the first record.</p>
  
  <p>I'm very new to node.js so I do not know if it's the good solution to embed several callback functions within the first callback function of app.get . How could I have the whole list returned ?</p>
  
  <p>Any idea ?</p>