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

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

    My problem was that when deploying to heroku I got an error:

    Web process failed to bind to $PORT within 60 seconds of launch

    when running heroku logs --tail in the terminal. BUT the application would run as expected when I ran the server locally.

    I had this in my index.js file (server file)

    const PORT = process.env.port || 4000
    
    app.listen(PORT, () => {
      console.log(`Server listening on port ${PORT}`)
    })
    

    But should have had this

    const PORT = process.env.PORT || 4000
    
    app.listen(PORT, () => {
      console.log(`Server listening on port ${PORT}`)
    })
    

    Use process.env.PORT, not process.env.port, because port is not the same as PORT obviously.

    Credit to gprasant.

提交回复
热议问题