0

I’m using the following to start a Node app on Cloud9 without getting the dreaded wrong port or IP warning, which I get unless I 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 on Heroku?

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
Chris
  • 471
  • 1
  • 3
  • 14
  • How did you define PORT? You need to define it with something like app.set('PORT', process.env.PORT || 5000). Then you should be able to do something like app.listen(app.get('PORT'), function() {...}). You should not have to pass a "host" parameter to app.listen at all. – Yoni Rabinovitch May 31 '18 at 06:12
  • I defined PORT in a separate config file and imported it. I think the problem is that according to Heroku support, you can't specify an IP address, only a port. So, I'm wondering how I can specify an IP when the app runs on Cloud9 but not when it runs on Heroku? I'd hate to have to write an `if` statement and have two different calls to `app.listen()`. – Chris Jun 01 '18 at 17:52
  • You don't need to specify an IP for C9 either. The code I sent you in my previous comment should work fine both on C9 and Heroku. Works fine for me on both. – Yoni Rabinovitch Jun 03 '18 at 06:02
  • Sounds like @YoniRabinovitch, has the answer here. Has this been resolved? From what I can tell after having tried to visit https://ancient-anchorage-15597.herokuapp.com, it has not. Can we come to a resolution by trying that code that was offered? – Daniel Jul 13 '18 at 11:16

0 Answers0