javascript - How to generate multiple response.write:s with json in node.js/express? -


having trouble generating multiple response.write:s api call in node.js. here code.

 // articles app.get('/api/articles', function(req, res) {   res.writehead(200, {     "content-type": "application/json" }); // use mongoose feeds in database feed.find(function(err, feeds) {     // if there error retrieving, send error. nothing after     res.send(err) execute     if (err)         res.send(err);      feeds.foreach(function(feedmodel) {         //for each feed in db articles via feed-read module         feed(feedmodel.url, function(err, articles) {             articles.foreach(function(articlemodel) {                 console.log(json.stringify(articlemodel));//works!!                 res.write(json.stringify(articlemodel));//doesnt produce output.             });         });     }); }); //end find function res.end(); }); //end api call 

you need end() inside callback no @ end.

res.end(json.stringify(articlemodel)); 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -