I am working on my first node.js / express / mongoose application and I ran into a problem due to the node.js asynchronization mechanism. It seems I am not doing it right ...
Here is a test route that I defined using an expression:
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);
When I exit http: // localhost / test , I would like to get a list of records like "MyModel" in the response.
The code above works fine, but when it comes to returning all this list to the client ... it does not work (comment line res.send) and returns only the first record.
I am very new to node.js, so I donβt know if this is a good solution to embed multiple callback functions in the first app.get callback function. How could I return the whole list?
Any idea?
source share