tmijs / tmi.js

💬 Javascript library for the Twitch Messaging Interface. (Twitch.tv)
https://tmijs.com
MIT License
1.55k stars 214 forks source link

Not able to change default port 80 by specifying it while deploying on Heroku (Error R10: Boot Timeout) #288

Closed ThatDNS closed 6 years ago

ThatDNS commented 6 years ago

Actual behaviour:

I've made a simple echo bot for twitch. Here is the source code -

var tmi = require('tmi.js');

const userChannel = process.env.CHANNEL;
const port1 = process.env.PORT || 80;

var options = {
    options: {
        debug: true
    },
    connection: {
        port: port1,
        reconnect: true
    },
    identity: {
        username: "testdns",
        password: process.env.OAUTH_TOKEN
    },
    channels: [userChannel]
};

var client = new tmi.client(options);
client.connect();

client.on('chat', function(channel, userstate, message, self){
    client.action(userChannel, message);
});

client.on('connected', function(address, port){
    console.log("Heroku port: " + process.env.PORT);
    console.log("App port: " + port);
    client.action(userChannel, "Welcome, I'm an echo bot.");
});

I set port to process.env.PORT || 80 so that it uses the PORT specified by Heroku instead of using default port 80 but the app doesn't even connect. I'm able to deploy the app perfectly on local machine after setting oauth token and channel name (config variables of Heroku).

Expected behaviour:

The app should use PORT given by Heroku and connect.

Heroku Error log:

2018-05-16T07:43:24.953782+00:00 app[api]: Release v42 created by user *********@gmail.com
2018-05-16T07:43:24.953782+00:00 app[api]: Deploy c66dc*** by user *********@gmail.com
2018-05-16T07:43:13.000000+00:00 app[api]: Build succeeded
2018-05-16T07:43:29.041467+00:00 heroku[web.1]: Starting process with command `npm start`
2018-05-16T07:43:32.038260+00:00 app[web.1]: 
2018-05-16T07:43:32.038278+00:00 app[web.1]: > susi_twitchbot@1.0.0 start /app
2018-05-16T07:43:32.038280+00:00 app[web.1]: > node app.js
2018-05-16T07:43:32.038281+00:00 app[web.1]: 
2018-05-16T07:44:29.161939+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-05-16T07:44:29.162057+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-05-16T07:44:29.301321+00:00 heroku[web.1]: Process exited with status 137
2018-05-16T07:44:29.374361+00:00 heroku[web.1]: State changed from starting to crashed
2018-05-16T07:44:29.376905+00:00 heroku[web.1]: State changed from crashed to starting
2018-05-16T07:44:32.157253+00:00 heroku[web.1]: Starting process with command `npm start`
2018-05-16T07:44:34.553007+00:00 app[web.1]: 
2018-05-16T07:44:34.553027+00:00 app[web.1]: > susi_twitchbot@1.0.0 start /app
2018-05-16T07:44:34.553029+00:00 app[web.1]: > node app.js
2018-05-16T07:44:34.553031+00:00 app[web.1]: 
2018-05-16T07:45:32.488610+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-05-16T07:45:32.488902+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-05-16T07:45:32.705175+00:00 heroku[web.1]: Process exited with status 137
2018-05-16T07:45:32.714247+00:00 heroku[web.1]: State changed from starting to crashed

Server configuration

ThatDNS commented 6 years ago

Please tell me how to solve this issue and successfully deploy this bot on Heroku. @AlcaDesign @Schmoopiie . Thanks a lot!

ThatDNS commented 6 years ago

If I don't change the PORT and let it be default port 80 meaning my "options" variable would look like this -

var options = {
    options: {
        debug: true
    },
    connection: {
        reconnect: true
    },
    identity: {
        username: "testdns",
        password: process.env.OAUTH_TOKEN
    },
    channels: [userChannel]
};

If I then try to deploy on Heroku, then these are the Heroku logs -

2018-05-16T07:58:17.058946+00:00 heroku[web.1]: Starting process with command `npm start`
2018-05-16T07:58:20.247479+00:00 app[web.1]: 
2018-05-16T07:58:20.247506+00:00 app[web.1]: > susi_twitchbot@1.0.0 start /app
2018-05-16T07:58:20.247508+00:00 app[web.1]: > node app.js
2018-05-16T07:58:20.247509+00:00 app[web.1]: 
2018-05-16T07:58:21.049407+00:00 app[web.1]: [07:58] info: Connecting to irc-ws.chat.twitch.tv on port 80..
2018-05-16T07:58:21.050056+00:00 app[web.1]: [07:58] info: Sending authentication to server..
2018-05-16T07:58:21.187016+00:00 app[web.1]: [07:58] info: Connected to server.
2018-05-16T07:58:21.187849+00:00 app[web.1]: Heroku port: 47622
2018-05-16T07:58:21.187953+00:00 app[web.1]: App port: 80
2018-05-16T07:58:21.190821+00:00 app[web.1]: [07:58] info: [#dns4044] *<testdns>: Welcome, I'm an echo bot.
2018-05-16T07:59:17.278362+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-05-16T07:59:17.278468+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-05-16T07:59:17.421805+00:00 heroku[web.1]: Process exited with status 137
2018-05-16T07:59:17.494698+00:00 heroku[web.1]: State changed from starting to crashed
2018-05-16T07:59:17.497126+00:00 heroku[web.1]: State changed from crashed to starting
2018-05-16T07:59:20.767032+00:00 heroku[web.1]: Starting process with command `npm start`
2018-05-16T07:59:24.063022+00:00 app[web.1]: 
2018-05-16T07:59:24.063062+00:00 app[web.1]: > susi_twitchbot@1.0.0 start /app
2018-05-16T07:59:24.063064+00:00 app[web.1]: > node app.js
2018-05-16T07:59:24.063066+00:00 app[web.1]: 
2018-05-16T07:59:26.335950+00:00 app[web.1]: [07:59] info: Connecting to irc-ws.chat.twitch.tv on port 80..
2018-05-16T07:59:26.336974+00:00 app[web.1]: [07:59] info: Sending authentication to server..
2018-05-16T07:59:26.484108+00:00 app[web.1]: [07:59] info: Connected to server.
2018-05-16T07:59:26.494716+00:00 app[web.1]: Heroku port: 13393
2018-05-16T07:59:26.496102+00:00 app[web.1]: App port: 80
2018-05-16T07:59:26.510634+00:00 app[web.1]: [07:59] info: [#dns4044] *<testdns>: Welcome, I'm an echo bot.
2018-05-16T08:00:20.833032+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-05-16T08:00:20.833276+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-05-16T08:00:20.966083+00:00 heroku[web.1]: Process exited with status 137
2018-05-16T08:00:20.993822+00:00 heroku[web.1]: State changed from starting to crashed
ThatDNS commented 6 years ago

It's solved! I added express module and used it to listen to the port provided by Heroku. Basically added these lines to my source code. 😄

const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
app.listen(port, () => {
   console.log(`listening on ${port}`);
});