Search code examples
node.jsherokudiscorddiscord.js

Heroku Error: Web process failed to bind to $PORT within 60 seconds of launch (With axios)


This is the full error code: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

A lot of answers to this say it has to do with setting your port as heroku does so dynamically, but if im using axios and not server.listen, and require a specific port for the mcsrv api, how would I go about fixing this problem?

I've already tried to set it to process.env.PORT with no avail (as well as using the || statement to set it to a default port)

 // Function for getting player counts
require('dotenv').config()

const axios = require('axios')

function pingForPlayers() {

    // Ping API for server data.

    axios.get(`https://api.mcsrvstat.us/2/play.lightningshot.net`)
    .then(response => {

        // If it gets a valid response

        if(response.data && response.data.players) {

            let playerCount = response.data.players.online || 0 // Default to zero

            info = `${playerCount}`

            client.channels.get('605543627208392875').setName("Players Online: " + info)

            // Could add console.log for more info, not necessary waste of cache data
        }

        else
            console.log('Could not load player count data for', process.env.MC_SERVER)


    }).catch(err => console.log('Error pinging api.mcsrvstat.us for data:', err))

}

Solution

  • Your app is not a webapp.

    You can add Procfile in your source:

    worker:  node index.js // (or your main file)
    

    And change to worker:

    • In Heroku dashboard, click tab resources
    • enter image description here and enable worker