Имея некоторые проблемы с созданием нескольких response.write: s из вызова api в node.js. Вот код.Как сгенерировать несколько response.write: s с json в node.js/express?
// get the articles
app.get('/api/articles', function(req, res) {
res.writeHead(200, {
"Content-Type": "application/json"
});
// use mongoose to get all feeds in the database
Feed.find(function(err, feeds) {
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
if (err)
res.send(err);
feeds.forEach(function(feedModel) {
//for each feed in db get 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
Hi! После некоторого вмешательства я получил его для работы, удалив строки res.writeHead и res.end. По-видимому, я буду запускать два writeHead с предыдущим кодом и удалив узел линий или экспресс будет «автоматически» исправлять заголовки. – user3422843
У меня появилась идея: http://stackoverflow.com/questions/17628052/nodejs-console-log-works-but-response-write-doesnt – user3422843