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

前端 未结 24 2479
梦如初夏
梦如初夏 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条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 06:29

    I had same issue but with express and apollo-server. The solution from here:

    The only special consideration that needs to be made is to allow heroku to choose the port that the server is deployed to. Otherwise, there may be errors, such as a request timeout.

    To configure apollo-server to use a port defined by Heroku at runtime, the listen function in your setup file can be called with a port defined by the PORT environment variable:

    > server.listen({ port: process.env.PORT || 4000 }).then(({ url }) => { 
    > console.log(`Server ready at ${url}`); });
    

提交回复
热议问题