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

前端 未结 24 2001
梦如初夏
梦如初夏 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:12

    For those that are passing both a port and a host, keep in mind that Heroku will not bind to localhost.

    You must pass 0.0.0.0 for host.

    Even if you're using the correct port. We had to make this adjustment:

    # port (as described above) and host are both wrong
    const host = 'localhost';
    const port = 3000;
    
    # use alternate localhost and the port Heroku assigns to $PORT
    const host = '0.0.0.0';
    const port = process.env.PORT || 3000;
    

    Then you can start the server, as usual:

    app.listen(port, host, function() {
      console.log("Server started.......");
    });
    

    You can see more details here: https://help.heroku.com/P1AVPANS/why-is-my-node-js-app-crashing-with-an-r10-error

提交回复
热议问题