title: Deploying to Heroku with Create-React-App and Node/Express: EADDRNOTAVAIL
body: <p>I have a MERN stack built using Facebook's Create-React-App template and Nodejs/Express that produces errors when deployed. I am using <a href="https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-nodejs" rel="nofollow noreferrer">Heroku's Nodejs Buildpack</a></p>
  
  <ol>
  <li><p>At first, when I deployed it after configuring my proxy for localhost, my app would only display "Invalid Host Header". <a href="https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#invalid-host-header-errors-after-configuring-proxy" rel="nofollow noreferrer">FB's docs</a> and <a href="https://github.com/facebook/create-react-app/issues/2271" rel="nofollow noreferrer">a Github Issue</a> recommended specifying the host and even dangerously disabling host check; I did both of these, and error #1 was gone but #2 arose even with my .env.development file with <code>HOST=my-heroku-app.herokuapp.com</code> (is this wrong?).
  (I also tried <a href="https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-eject" rel="nofollow noreferrer">ejecting</a> so I could disable host check manually <a href="https://stackoverflow.com/questions/43619644/i-am-getting-an-invalid-host-header-message-when-running-my-react-app-in-a-we">as described here</a> but this also brought me to my next error.)</p></li>
  <li><p>Now I just got a Heroku application error, with the following log:</p>
  
  <pre><code>2018-03-04T03:02:49.270931+00:00 heroku[web.1]: - Restarting
  2018-03-04T03:02:49.271285+00:00 heroku[web.1]: - State changed from up to starting
  2018-03-04T03:02:04.000000+00:00 app[api]: - Build succeeded
  2018-03-04T03:02:50.294779+00:00 heroku[web.1]: - Stopping all processes with SIGTERM
  2018-03-04T03:02:50.404316+00:00 heroku[web.1]: - Process exited with status 143
  2018-03-04T03:02:57.240490+00:00 heroku[web.1]: - Starting process with command `react-scripts start`
  2018-03-04T03:03:01.011562+00:00 heroku[web.1]: - Process exited with status 1
  2018-03-04T03:03:01.038935+00:00 heroku[web.1]: - State changed from starting to crashed
  2018-03-04T03:03:01.040756+00:00 heroku[web.1]: - State changed from crashed to starting
  2018-03-04T03:03:00.918201+00:00 app[web.1]: - Could not find an open port at myapp.herokuapp.com.
  2018-03-04T03:03:00.918218+00:00 app[web.1]: - Network error message: listen EADDRNOTAVAIL 54.235.183.213
  2018-03-04T03:03:11.873080+00:00 heroku[web.1]: - State changed from starting to crashed
  2018-03-04T03:03:11.856257+00:00 heroku[web.1]: - Process exited with status 1
  2018-03-04T03:03:14.126300+00:00 heroku[router]: - at=error code=H10 desc="App crashed" method=GET path="/" host=mysite.herokuapp.com request_id=a688b1cb-d756-4201-a056-25d65ad13de1 fwd="ip_of_my_site" dyno= connect= service= status=503 bytes= protocol=https
  </code></pre>
  
  <p>Here's my code for setting up the server</p>
  
  <pre><code>const port = process.env.PORT || 3001;
  //starts the server and listens for requests
  app.listen(port, function () {
      debug(`api running on port ${port}`);
  });
  </code></pre></li>
  </ol>
  
  <p>I've tried <a href="https://stackoverflow.com/questions/10809740/listen-eaddrnotavail-error-in-node-js">changing the port and host</a> as suggested here with no luck. </p>
  
  <p>What can I do to resolve this error in heroku? Let me know if I should provide any additional information. Thanks.</p>
  
  <p>EDIT: package.json</p>
  
  <pre><code>{
    "name": "my_project",
    "version": "0.1.0",
    "private": true,
    "proxy": "http://localhost:3001/",
    "dependencies": {
      "@sendgrid/mail": "^6.2.1",
      "async": "^2.6.0",
      "aws-sdk": "^2.205.0",
      "axios": "^0.14.0",
      "body-parser": "~1.17.1",
      "cookie-parser": "~1.4.3",
      "cors": "^2.8.4",
      "debug": "^2.6.9",
      "dotenv": "^5.0.1",
      "express": "~4.15.2",
      "express-fileupload": "^0.4.0",
      "font-awesome": "^4.7.0",
      "foreman": "^2.0.0",
      "history": "^4.7.2",
      "marked": "^0.3.17",
      "milligram": "^1.3.0",
      "milligram-react": "0.0.0",
      "mongodb": "^2.2.35",
      "mongoose": "^4.13.11",
      "morgan": "~1.8.1",
      "nodemailer": "^4.6.0",
      "nodemon": "^1.17.1",
      "react": "^16.2.0",
      "react-bootstrap": "^0.32.1",
      "react-dom": "^16.2.0",
      "react-fontawesome": "^1.6.1",
      "react-icons": "^2.2.7",
      "react-onclickoutside": "^6.7.1",
      "react-router": "^4.2.0",
      "react-router-dom": "^4.2.2",
      "react-scripts": "1.0.17",
      "react-table": "^6.8.0",
      "sendgrid-web": "0.0.5",
      "serve-favicon": "~2.4.2",
      "supports-color": "^5.3.0"
    },
    "scripts": {
      "start": "react-scripts start | node server.js",
      "start-dev": "set DEBUG=* &amp; nodemon server.js",
      "build": "react-scripts build",
      "test": "react-scripts test --env=jsdom",
      "eject": "react-scripts eject"
    }
  }
  </code></pre>