0

I deployed my NodeJS app to Heroku with no issues but when i try to access the website it doesn't show up and the logs say its because the app crashed. Before that it says "Something is already running on port ___ (number changes)" See below for full logs.

I don't have the PORT defined anywhere so I'm not sure whats causing the issue

2023-04-23T01:48:31.153091+00:00 heroku\[web.1\]: State changed from starting to up
2023-04-23T01:48:31.985212+00:00 app\[web.1\]: (node:94) \[DEP0111\] DeprecationWarning: Access to process.binding('http_parser') is deprecated.
2023-04-23T01:48:31.985224+00:00 app\[web.1\]: (Use `node --trace-deprecation ...` to show where the warning was created)
2023-04-23T01:48:31.994899+00:00 app\[web.1\]: Something is already running on port 54962.
2023-04-23T01:48:32.144102+00:00 heroku\[web.1\]: Process exited with status 0
2023-04-23T01:48:32.215276+00:00 heroku\[web.1\]: State changed from up to crashed
2023-04-23T01:51:22.767165+00:00 heroku\[router\]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.novacancytrans.com request_id=807a004d-266d-4b22-8853-0017d0f41a74 fwd="72.207.46.240" dyno= connect= service= status=503 bytes= protocol=http
2023-04-23T01:51:23.584384+00:00 heroku\[router\]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=www.novacancytrans.com request_id=d216e51a-ac49-4f54-9816-821b430d18fd fwd="72.207.46.240" dyno= connect= service= status=503 bytes= protocol=http

Here is my package.json

{
  "name": "no-vacancy",
  "version": "1.0.0",
  "main": "server.js",
  "engines": {
    "node": "16.x",
    "npm": "8.x"
  },
  "scripts": {
    "start": "npx if-env NODE_ENV=production && npm run start:prod || npm run start:dev",
    "start:prod": "node server.js && cd client/\* & npm run client",
    "start:dev": "node server.js && cd client/\* & npm run client",
    "client": "cd client && npm run start",
    "install": "cd client && npm install",
    "build": "cd client && npm run build",
    "heroku-postbuild": "npm run build"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "bulma": "^0.8.0",
    "concurrently": "^8.0.1",
    "morgan": "^1.9.1"
  },
  "dependencies": {
    "@material-ui/core": "^4.5.1",
    "@material/typography": "^3.1.0",
    "ag-grid-react": "28.2.1",
    "ag-grid-community": "^28.2.1",
    "axios": "^0.19.0",
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "classnames": "^2.2.6",
    "concurrently": "^8.0.1",
    "dotenv": "^8.1.0",
    "express": "^4.17.1",
    "formik": "^1.5.8",
    "google-map-react": "^1.1.5",
    "google-maps-react": "^2.0.2",
    "http-proxy-middleware": "^0.20.0",
    "if-env": "^1.0.4",
    "is-empty": "^1.2.0",
    "jsonwebtoken": "^8.5.1",
    "jwt-decode": "^2.2.0",
    "mapbox-gl": "^1.5.0",
    "material-paper": "0.0.8",
    "moment": "^2.24.0",
    "mongodb": "^3.3.2",
    "mongodb-stitch-browser-sdk": "^4.5.0",
    "mongoose": "^5.7.5",
    "mongoose-geojson-schema": "^2.1.3",
    "mongoose-geojson-schemas": "^0.10.13",
    "nodemailer": "^6.8.0",
    "passport": "^0.4.0",
    "passport-jwt": "^4.0.0",
    "react": "^16.10.1",
    "react-datepicker": "^2.9.6",
    "react-dom": "^16.10.2",
    "react-google-maps": "^9.4.5",
    "react-redux": "^7.1.1",
    "react-router-dom": "^5.0.1",
    "redux": "^4.0.4",
    "redux-thunk": "^2.3.0",
    "semantic-ui-css": "^2.4.1",
    "semantic-ui-react": "^0.88.2",
    "validator": "^11.1.0",
    "yup": "^0.27.0"
  }
}

Procfile

web: npm start

Server.js File has the following code at the end:

app.get("\*", function(req, res) {
  res.sendFile(path.join(\__dirname, "./client/build/index.html"));
});
const PORT = process.env.PORT || 5000;

app.listen(PORT, function() {
  console.log(` ==> API server now on port ${PORT}!`);
});

A few things I tried is running heroku restart in the terminal, deploying the previous working branch since before my deploy, the website was running. Neither worked. If anyone knows what to do I'd greatly appreciate the assist!

Zac Anger
  • 6,983
  • 2
  • 15
  • 42
  • `start` runs `start:prod` (or `start:dev`, but those _do the exact same thing_ so why you have two separate scripts I don't know), which runs `client`, which runs `start`. These scripts are quite weird, definitely fix those up. – Mike 'Pomax' Kamermans Apr 23 '23 at 04:19
  • They're not written the best, but I don't think its the script because when it deploys i don't get any issues with the build. Its only after the application starts running on the PORT defined by Heroku that I get an issue. For some reason Heroku chooses the PORT then says that same PORT is being used. – Kat Vengoechea Apr 23 '23 at 04:26

1 Answers1

0

It looks like you're running two apps. You didn't include what npm start means in client, but that probably means two Node servers (even if the client one is coming from some framework, rather than your own code). Heroku dynamically assigns you one IP address. If you only serve your client from your server, there won't be a conflict.

See also this, this, this, and the docs.

Zac Anger
  • 6,983
  • 2
  • 15
  • 42
  • The client folder has the front end code thats using react (create react app) and server.js is starting up the back end for the api's and the database. I am serving up the index.html file (app.get("\*", function(req, res) { res.sendFile(path.join(\__dirname, "./client/build/index.html")); });). I've had this code for four years though and its only stopped working suddenly after this initial deploy when i changed the heroku stack from the deprecated 18 to 22. – Kat Vengoechea Apr 23 '23 at 04:50
  • Then what does `npm run client` do? – Zac Anger Apr 23 '23 at 05:00
  • It runs the client portion of the script: "client": "cd client && npm run start", – Kat Vengoechea Apr 24 '23 at 22:22
  • Right, so what is the `start` script in the `client` directory? – Zac Anger Apr 24 '23 at 22:27