Avoiding IP and PORT errors and deploying to Heroku


#1

I’m using the following to start a Node app on C9 without getting the dreaded wrong port or IP warning, which I get if I don’t specify the IP address as process.env.IP:

  app.listen(PORT, process.env.IP || 'localhost', function () {
    console.info(`Server listening on ${this.address().address}:${this.address().port}`);
  }).on("error", err => {
    console.error(err);
  });

However, I’m wondering when I deploy this to Heroku and process.env.IP is undefined, is it O.K. that the IP will default to localhost?


#2

When I try running this on Heroku, I get this from the console.info:

Server listening on 127.0.0.1:23128

but then I get the following errors in the Heroku log:

2018-05-31T04:36:26.982797+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-05-31T04:36:26.982904+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-05-31T04:36:27.097924+00:00 heroku[web.1]: State changed from starting to crashed
2018-05-31T04:36:27.074917+00:00 heroku[web.1]: Process exited with status 137
2018-05-31T04:37:18.807726+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ancient-anchorage-15597.herokuapp.com request_id=f893c181-f406-4319-b2f2-938548ba4ff0 fwd="72.0.178.64" dyno= connect= service= status=503 bytes= protocol=https

#3

So, I heard back from Heroku support and apparently you can’t specify an IP on their system. Hard to believe there’s no way to create an app in C9 and deploy it to Heroku without getting this warning in the C9 console:

Cloud9 Help
You may be using the wrong PORT & IP for your server application.Try passing $PORT and $IP to properly launch your application. You can find more information in our docs.