Global Feed - Backend Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
let stream = require('getstream'); | |
const app = express() | |
const port = 3000 | |
const STREAM_API_KEY='qkswp9afyz49' | |
const STREAM_API_TOKEN='5fjsqcda7keu2v7s2tfmqyw2z3bedcm3d3f86jhmeu3fawhsace9apuda8chgm5k' | |
app.get('/', async (req, res) => { | |
// Connection to GetStream client | |
let client = await stream.connect(STREAM_API_KEY, STREAM_API_TOKEN); | |
// User private token creation | |
let userToken = await client.createUserToken('timeline'); | |
// User creation | |
await client.user('tester').getOrCreate({ | |
name: "Tester", | |
fullname: 'Tester', | |
}) | |
// Addin user to a feed and to follow feed's activities | |
const timelineFeed = client.feed('timeline', 'timeline') | |
timelineFeed.follow('user', 'tester') | |
// Return private token and user id | |
res.send({userToken, userId: 'tester'}) | |
}) | |
app.listen(port, () => { | |
console.log(`Backend api listening at http://localhost:${port}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment