Skip to content

Instantly share code, notes, and snippets.

@nparsons08 nparsons08/3.js Secret
Created May 28, 2019

Embed
What would you like to do?
// index.js
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const { StreamChat } = require('stream-chat')
require('dotenv').config()
const app = express()
const port = 3000
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
// initialize Stream Chat SDK
const serverSideClient = new StreamChat(
process.env.STREAM_API_KEY,
process.env.STREAM_APP_SECRET
)
app.post('/join', async (req, res) => {
const { username } = req.body
// generate Stream Chat token to use to authenticate user on the client
const token = serverSideClient.createToken(username)
return res.status(200).json({ user: { username }, token })
})
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.