Search code examples
javascriptnode.jsmongodbexpressgetstream-io

How to build a news feed with getstream.io in Node.js?


const stream = require('getstream');

//newsfeed stream
const client = stream.connect( null, );

var user1 = client.feed('user', 'user1');

// Add activity; message is a custom field - tip: you can add unlimited custom fields!
user1.addActivity({
  actor: 'user1',
  verb: 'add',
  object: 'picture:10',
  foreign_id: 'picture:10',
  "time": now.toISOString(),
});

// jack's 'timeline' feed follows chris' 'user' feed:
var jack = client.feed('timeline', 'jack');
jack.follow('user', 'user1');

// Read 'timeline' for jack - the post by chris will show up:
jack.get({ limit: 10 }).then(function(results) {
  var activityData = results;

  // Read the next page, using id filtering for optimal performance:
  jack.get({ limit: 10, id_lte: activityData[activityData.length-1].id }).then(function(results) {
    var nextActivityData = results;
  });
});

// Remove activity by referencing foreign_id:
user1.removeActivity({ foreign_id: 'picture:10' });

In this example I'm in using the code provide to me to create a newsfeed with getstream.io. I have not done anything like this before, so I don't know where to start.


Solution

  • We have a Node-specific "Pinterest" example app you can use to get started, https://github.com/GetStream/Stream-Example-Nodejs

    I also recommend you check out our blog post on tips to make a news feed that's really engaging, https://getstream.io/blog/13-tips-for-a-highly-engaging-news-feed/