Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch)

前端 未结 24 1991
梦如初夏
梦如初夏 2020-11-22 05:42

I have my first node.js app (runs fine locally) - but I am unable to deploy it via heroku (first time w/ heroku as well). The code is below. SO doesn\'t let me write so much

相关标签:
24条回答
  • 2020-11-22 06:16

    I had the same issue because I didn't define Procfile. Commit a text file to your app's root directory that is named Procfile without a file extension. This file tells Heroku which command(s) to run to start your app.

    web: node app.js
    
    0 讨论(0)
  • 2020-11-22 06:16

    A fixed number can't be set for port, heroku assigns it dynamically using process.env.PORT. But you can add them both, like this process.env.PORT || 5000. Heroku will use the first one, and your localhost will use the second one.

    You can even add your call back function. Look at the code below

    app.listen(process.env.PORT || 5000, function() {
        console.log("Server started.......");
    });
    
    0 讨论(0)
  • 2020-11-22 06:19

    I had same issue while using yeoman's angular-fullstack generated project and removing the IP parameter worked for me.

    I replaced this code

    server.listen(config.port, config.ip, function () {
      console.log('Express server listening on %d, in %s mode', config.port, app.get('env'));
    });
    

    with

    server.listen(config.port, function () {
      console.log('Express server listening on %d, in %s mode', config.port, app.get('env'));
    });
    
    0 讨论(0)
  • 2020-11-22 06:22

    In my case, I was using example from https://hapijs.com/

    To fix the problem I replaced

    server.connection({ 
        host: 'localhost', 
        port: 8000 
    });
    

    with

    server.connection({
        port: process.env.PORT || 3000 
    });
    
    0 讨论(0)
  • 2020-11-22 06:22

    Changing my listening port from 3000 to (process.env.PORT || 5000) solved the problem.

    0 讨论(0)
  • 2020-11-22 06:22

    I had same issue I could resolved issue with replace 'localhost' with IP which is '0.0.0.0'

    0 讨论(0)
提交回复
热议问题