JavaScript doesn't use $
prefixes for variables, but the example code you've given above also does not build a variable called token
of any kind.
There are two client connections you can make with the stream-js library:
One happens in your Node.js application that runs on the server, and that one you would pass your API key and API secret. This gives you a read-write connection to Stream to read feeds but also to write activities, perform follow relationships, and to delete/update activities and unfollow other feeds, etc.
The other client would happen in the browser (where your API secret is null
) but requires a token that gets generated by your back-end/server application and allows a read-only connection to Stream over websockets for real-time notifications. Your account has a limit on how many active websocket connections your browser clients can make to Stream.
As far as generating the token for the websocket connection, you would use code like this on the server-side:
backendClient = stream.connect(<API_KEY>, <API_SECRET>, <APP_ID>)
readonlyToken = backendClient.feed('user', '1').getReadOnlyToken();
This generates a read-only token for the user:1
feed but cannot perform write functions like adding/editing/updating activity data or follow/unfollows, etc..
Then, you'd get that token to your front-end browser/client however you like. From there, then, the front-end client would make a connection to Stream using code like this:
browserClient = stream.connect('q3nwu4pbz222', null, '25553');
user1 = browserClient.feed('user', '1', readonlyToken);
user1.get({limit:5}, callbackWhenFinished);