0

On my back end, I am getting a stream that contains the data from a website that contains much more information than is being sent from my route. From this code:

feedparser.on('readable', function(){
    var stream = this;
    var meta = this.meta;
    var item;

    while(item=stream.read()){
        theNews = item;
        console.log(JSON.stringify(theNews));
    }
});

news.post('/', function(req, res){
    var currentNews = JSON.stringify(theNews);
    console.log(currentNews);
    res.send(currentNews);
});

the console.log in feedparser.on returns an object with many news articles. When I console log it in that scope, it shows all the articles properties such as title, description, link, etc... It takes up the entire cmd console log giving me over 80,000 characters because it includes multiple articles.

However, the console.log from news.post and the response it sends is only the oldest object in the stream which is one article. Why?

EDIT: NM I was able to figure it out. I had to set theNews as an array and then push item into it as it.

1 Answers1

0

The stream was streaming the data as it grabbed it and it did it really rapidly so the output was multiple streams that looked like one file. In reality, I was only setting the variable to the last item streamed. By using an array and pushing into it I was able to get all the information.