Home > Mobile >  Heroku Node.js: Web process failed to bind to $PORT within 60 seconds of launch
Heroku Node.js: Web process failed to bind to $PORT within 60 seconds of launch

Time:07-16

I built a Node.js/Express Web Api. I want to deploy it on Heroku. It works fine on local but when I deploy it I get the following error:

 Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

index.js

app.listen(process.env.PORT || 3000, () => {
    console.log(`app running on ${process.env.PORT}`);
});

.env

PORT=3000

I have configured the PORT variable on Heroku -> Settings ->Config Vars section. However it didn't solve my problem.

Additionally, when I look up the application logs on Heroku, the callback function on the listen() method, outputs the following:

2022-07-15T20:06:19.268954 00:00 app[web.1]: app running on undefined 
2022-07-15T20:06:20.230943 00:00 app[web.1]: connected to db

connected to db output came from mongodb connection. My app also gets the mongodb credentials from .env file and it works fine. But why I can't get PORT variable and it returns undefined?

CodePudding user response:

This is a duplicate of this question and the answer is - PORT variable is provided by Heroku and you can't set it.

CodePudding user response:

I removed the PORT variable either on .env file or Config Vars on Heroku. And I change the way to call the PORT variable to not conflict with Heroku's default PORT.

index.js

let port = process.env.PORT || 3000;

app.listen(port, () => {
  console.log(`app running on ${port} `);
});

App runs on 3000 port in localhost and Heroku's default port in server now.

  • Related