SaraRandolph
SaraRandolph

Reputation: 53

Heroku: Something is already running on port

I am new to Heroku and I'm attempting to deploy my node server and create-react-app front end application. Everything runs great locally but when I try to run it on Heroku it all goes down in flames. I get no deploy errors and I only see Cannot GET / at my URL.

My logs say:

Something is already running on port 12345

/server/app.js

var express = require('express');
var app = express();
require('dotenv').config();
var mongoose = require('mongoose');
var config = require('./config');
var apiController = require('./controllers/apiController');

var port = process.env.PORT || 3005;

app.use('/', express.static(__dirname + '/public'));

app.set('view engine', 'ejs');

mongoose.connect(config.getDbConnectionString());
apiController(app);

app.listen(port);

package.json

{
  "name": "happy-holidays",
  "version": "1.0.0",
  "description": "",
  "engines": {
    "node": "8.9.4"
  },
  "scripts": {
    "start": "concurrently --kill-others-on-fail \"yarn run server\" \"yarn run client\"",
    "server": "cd server && yarn start",
    "client": "cd react-ui && yarn start"
  },
  "license": "UNLICENSED" ,
  "cacheDirectories": [
    "node_modules",
    "react-ui/node_modules"
  ],
  "dependencies": {
    "@sendgrid/mail": "^6.2.1",
    "axios": "^0.18.0",
    "body-parser": "^1.18.2",
    "bootstrap": "^4.1.1",
    "concurrently": "^3.5.1",
    "dotenv": "^5.0.1",
    "ejs": "^2.6.1",
    "express": "^4.16.3",
    "mongoose": "^5.1.0",
    "react": "^16.3.2",
    "react-bootstrap": "^0.32.1",
    "react-dom": "^16.3.2",
    "react-router-dom": "^4.2.2",
    "react-scripts": "1.1.4",
    "semantic-ui-css": "^2.3.1",
    "semantic-ui-react": "^0.80.2"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/SaraRandolph/messagez"
  },
  "devDependencies": {}
}

Upvotes: 0

Views: 1901

Answers (4)

ukpeti
ukpeti

Reputation: 21

The same problem has been solved here: Strange Create-React-App Heroku Error - Cannot GET /

it is because you're not serving the index.html file from your express server.

so you have to copy into your server.js file

  if (process.env.NODE_ENV === 'production') {
  // Exprees will serve up production assets
  app.use(express.static('client/build'));

  // Express serve up index.html file if it doesn't recognize route
  const path = require('path');
  app.get('*', (req, res) => {
    res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
  });
}

Upvotes: 0

ukpeti
ukpeti

Reputation: 21

"Why the port 12345 is coming instead of 3005 ?"

Because HEROKU assigns a PORT dynamically.

Upvotes: 1

Aaron J
Aaron J

Reputation: 389

Not sure what your react-ui start script look like, but you probably need to run that first, before your server start script. Idealy you want to run just a distribution build for your react-ui and then serve up that build ui bundle in your server script.

Upvotes: 0

Saif
Saif

Reputation: 3452

Try

const port = process.env.PORT || 5000

This works for my app.

Try to have the app configured like this getting stated app from Heroku

Copy the scripts from the package.json and the Procfile.

Upvotes: 0

Related Questions