Nylsoo
Nylsoo

Reputation: 159

Heroku process.env.port is undefined

I am trying to run a node.js app on heroku. I got it working local, but when i deploy it on heroku i get the following error:

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

This is the port i try to listen to:

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

When i logged what the process.env.port was it said process.env.port was undefined.

Is there anything i need to do to automatically set the port?

Edit (FIX): So i found out where the problem was. The javascript was being minified, but the process.env.port was minified to something that didn't work. Thanks for the help.

Upvotes: 4

Views: 14270

Answers (4)

RazerMoon
RazerMoon

Reputation: 45

Just wanted to leave this for anybody who was confused like me, you have to use

process.env.PORT

NOT

process.env.$PORT

Upvotes: 0

med morad
med morad

Reputation: 509

for any one get to that post. first check if you are writing process.env.PORT correctly. I was writing .Port and it took 4 hours of my life to figure out the error

Upvotes: 7

Bayramali Başgül
Bayramali Başgül

Reputation: 200

I had the same issue and found the solution to pass heroku dyno port variable to node start script.

If you have created a Procfile in your root directory of your project just open it.

If you haven't created a Procfile just go to root directory of your project and create a file called "Procfile". The file has no extension and it helps to heroku get the starter point of your application. More details about it: The Procfile

In Node.JS Heroku documentation there isn't provided any example how should look like Procfile.

In my case, I'm using Typescript and my output directory of .js files is in /build directory in my project folder. and I'm assuming that you have the same situation. If not, just put your starter file's directory.

Procfile:

web: PORT=$PORT node ./build/index.js

Upvotes: 3

Edgar Ortega
Edgar Ortega

Reputation: 1735

If you're using babel, do not use the babel plugin babel-plugin-transform-inline-environment-variables in Heroku. I think Heroku does not set the PORT variable when doing a deployment, so that's why you would get undefined.

Upvotes: 0

Related Questions