Note that there is also a higher level Node integration which hooks into your ORM.
You can sign up for a Stream account at https://getstream.io/get_started.
Install from NPM
npm install getstream
Using JS deliver
Install by downloading the JS file
Using with React Native
This package can be integrated into React Native applications. Remember to not expose the App Secret in browsers, "native" mobile apps, or other non-trusted environments.
API client setup Node
var stream = ;// Instantiate a new client (server side)client = stream;// Optionally supply the app identifier and an object specifying the data center to useclient = stream;
API client setup Node + Browser
If you want to use the API client directly on your web/mobile app you need to generate a user token server-side and pass it.
Server-side token generation
var stream = ;// Instantiate a new client (server side)client = stream;// Optionally supply the app identifier and an object specifying the data center to useclient = stream;// Create a token for user with id "the-user-id"const userToken = client;
Client API init
var stream = ;// Instantiate new client with a user tokenclient = stream;
// Instantiate a feed object server sideuser1 = client;// Get activities from 5 to 10 (slow pagination)user1;// Filter on an id less than a given UUIDuser1;// All API calls are performed asynchronous and return a Promise objectuser1;// Create a new activityactivity = 'actor': 1 'verb': 'tweet' 'object': 1 'foreign_id': 'tweet:1';user1;// Create a bit more complex activityactivity = 'actor': 1 'verb': 'run' 'object': 1 'foreign_id': 'run:1''course': 'name': 'Golden Gate park' 'distance': 10'participants': 'Thierry' 'Tommaso''started_at':;user1;// Remove an activity by its iduser1;// or remove by the foreign iduser1;// mark a notification feed as readnotification1 = client;var params = mark_read: true;notification1;// mark a notification feed as seenvar params = mark_seen:true;notification1;// Follow another feeduser1;// Stop following another feeduser1;// Stop following another feed while keeping previously published activities// from that feeduser1;// Follow another feed without copying the historyuser1;// List followers, followinguser1;user1;// all methods support callback as the last argumentuser1;// adding multiple activitiesactivities ='actor': 1 'verb': 'tweet' 'object': 1'actor': 2 'verb': 'tweet' 'object': 3;user1;// specifying additional feeds to push the activity to using the to param// especially useful for notification style feedsto = 'user:2' 'user:3';activity = 'to': to 'actor': 1 'verb': 'tweet' 'object': 1 'foreign_id': 'tweet:1';user1;// adding one activity to multiple feedsvar feeds = 'flat:1' 'flat:2' 'flat:3' 'flat:4';activity ='actor': 'User:2''verb': 'pin''object': 'Place:42''target': 'Board:1';// ⚠️ server-side only!client;// Batch create follow relations (let flat:1 follow user:1, user:2 and user:3 feeds in one single request)var follows ='source': 'flat:1' 'target': 'user:1''source': 'flat:1' 'target': 'user:2''source': 'flat:1' 'target': 'user:3';// ⚠️ server-side only!client;// Updating parts of an activityvar set ='product.price': 1999'shares':'facebook': '...''twitter': '...'var unset ='daily_likes''popularity'// ...by IDclient// ...or by combination of foreign ID and timeclient// ⚠️ server-side only!// Create redirect urlsvar impression ='content_list': 'tweet:1' 'tweet:2' 'tweet:3''user_data': 'tommaso''location': 'email''feed_id': 'user:global';var engagement ='content': 'tweet:2''label': 'click''position': 1'user_data': 'tommaso''location': 'email''feed_id':'user:global';var events = impression engagement;var redirectUrl = client;// update the 'to' fields on an existing activity// client.feed("user", "ken").function (foreign_id, timestamp, new_targets, added_targets, removed_targets)// new_targets, added_targets, and removed_targets are all arrays of feed IDs// either provide only the `new_targets` parameter (will replace all targets on the activity),// OR provide the added_targets and removed_targets parameters// NOTE - the updateActivityToTargets method is not intended to be used in a browser environment.clientclientclient
Stream uses Faye for realtime notifications. Below is quick guide to subscribing to feed changes
var stream = ;// ⚠️ userToken is generated server-side (see previous section)client = stream;user1 = client;// subscribe to the changesvar subscription = user1;// now whenever something changes to the feed user 1// the callback will be called// To cancel a subscription you can call cancel on the// object returned from a subscribe call.// This will remove the listener from this channel.subscription;
Docs are available on GetStream.io.
Node version requirements & Browser support
This API Client project requires Node.js v6 at a minimum.
The project is supported in line with the Node.js Foundation Release Working Group.
First, make sure you can run the test suite. Tests are run via Mocha
mocha test/integration/index.js test/unit/index.js# browser version (needs to be build through gulp build:test)test/browser/test.html# coveragemocha test/cov.js -R html-cov > cov.html
Copyright and License Information
Copyright (c) 2015-2018 Stream.io Inc, and individual contributors. All rights reserved.
See the file "LICENSE" for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.