Reputation: 2582
I'm currently using botkit-sms with Node and Express, deployed on Heroku to create a mobile application that can send SMS messages to users who aren't yet signed up. In my server.js
file, I open ports for the API and the messaging bot, which works locally but breaks when I deploy to Heroku. I get the error Error: listen EADDRINUSE :::56136
. I know this is because both are trying to use process.env.PORT. Is there a way I can fix this?
Relevant code:
import express from 'express';
const app = express();
const TwilioSMSBot = require('botkit-sms')
const controller = TwilioSMSBot({
account_sid: ACCOUNT_ID,
auth_token: AUTH_TOKEN,
twilio_number: TWILIO_NUMBER
})
const port = process.env.PORT || 9090;
app.listen(port);
app.get('/', (req, res) => {
res.send('hi');
});
let bot = controller.spawn({})
controller.setupWebserver(process.env.PORT || 3001, function (err, webserver) {
controller.createWebhookEndpoints(controller.webserver, bot, function () {
console.log('TwilioSMSBot is online!')
})
})
Upvotes: 1
Views: 9045
Reputation: 1
It IS possible to use different ports on Heroku, as long as the default port (named $PORT) is among those.
See here for an exmple of multiple ports used: https://stackoverflow.com/a/43911373/9646899
Upvotes: 0