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
?
This is a duplicate of this question and the answer is - PORT
variable is provided by Heroku and you can't set it.