Skip to content

Instantly share code, notes, and snippets.

@altanai
Created February 24, 2021 19:46
Show Gist options
  • Save altanai/99a7cb29e31d160cab32805e47dbe8b5 to your computer and use it in GitHub Desktop.
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
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);
@altanai
Copy link
Author

altanai commented Feb 24, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment