Created
February 24, 2021 19:46
-
-
Save altanai/99a7cb29e31d160cab32805e47dbe8b5 to your computer and use it in GitHub Desktop.
Express web-server with API endpoint to get Twilio STUN/TURN with realtime token
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
require('dotenv').config(); | |
console.log('Environment variable TWILIO_ACCOUNT_SID has the value: ', process.env.TWILIO_ACCOUNT_SID); | |
const accountSid = process.env.TWILIO_ACCOUNT_SID; | |
const authToken = process.env.TWILIO_AUTH_TOKEN; | |
const client = require('twilio')(accountSid, authToken); | |
const app = require('express')(); | |
const bodyParser = require('body-parser'); | |
app.use(bodyParser.json()); // for parsing application/json | |
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded | |
app.post('/', (req, res, next) => { | |
console.log(req); | |
client.tokens.create() | |
.then(token => { | |
console.log(token); | |
res.send(token); | |
}) | |
.catch(err=>{ | |
console.error(err); | |
}); | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full project https://github.com/altanai/twillio_turn