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

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

    Heroku dynamically assigns your app a port, so you can't set the port to a fixed number. Heroku adds the port to the env, so you can pull it from there. Switch your listen to this:

    .listen(process.env.PORT || 5000)
    

    That way it'll still listen to port 5000 when you test locally, but it will also work on Heroku.

    You can check out the Heroku docs on Node.js here.

提交回复
热议问题