Something is already running on that PORT

ethancs13TRIAL

a year ago

Currently I am setting up an app on railway using mySql and a react front end. Currently I have correctly setup the server so that it connects to the sql server, but the server.js file I have keeps getting an error that the port is being used. I have left the PORT variable empty and then it defaults to 8080 which is still being used. I have tried other PORTS to find one, but to no avail.

How do I find the correct port?

77 Replies

a year ago

Please share your github repo.


ethancs13TRIAL

a year ago

https://github.com/ethancs13/dbdbdb


a year ago

Okay there's a few simple things you are doing wrong -

  • You are trying to run two apps (client and server) inside of one Railway service.

  • Your client is running a development server.

  • You are attempting to use nodemon in production.

So let's work through the steps one at a time for simplicity sake.

First off, copy the nixpacks.toml and Caddyfile from this repo into your client folder - https://github.com/brody192/create-react-app-starter


ethancs13TRIAL

a year ago

I see, done!


a year ago

I'm not seeing any changes in your repo?


ethancs13TRIAL

a year ago

Should be there


ethancs13TRIAL

a year ago

In the client folder, correct?


a year ago

Your Caddyfile is named Caddyfile.txt


ethancs13TRIAL

a year ago

That is what it defaulted to when I downloaded the file


ethancs13TRIAL

a year ago

I will fix that


a year ago

It is incorrect, the file should not have an extension.


ethancs13TRIAL

a year ago

Okay, I pushed the change


a year ago

Looks good, please attach a screenshot of the project canvas on Railway.


ethancs13TRIAL

a year ago

Is this the canvas?

Attachments


a year ago

Yes it is, but for future reference, please do not crop the screenshots.

This will be the client service, open it's settings and set the root directory to /client


ethancs13TRIAL

a year ago

like this?

Attachments


a year ago

Correct, deploy the changes.


ethancs13TRIAL

a year ago

The app is deployed! Thank you so much for your help


a year ago

We aren't done, that is only the client.


ethancs13TRIAL

a year ago

Okay, but that part works! Thank you


a year ago

Go ahead and deploy MySQL into the same project, and then attach a screenshot of the canvas.


ethancs13TRIAL

a year ago

what do you mean by that exactly sorry


a year ago

Your server needs MySQL doesn't it? therefore you need to deploy MySQL into the project.


ethancs13TRIAL

a year ago

The mysql server I have is hosted on an aws rds. I have already gotten the app to connect to the db successfully


ethancs13TRIAL

a year ago

Here is the endpoint mysqlinstance.cx46082i6vq9.us-east-2.rds.amazonaws.com


a year ago

Ah okay, I had no clue you were not going to be using MySQL on Railway.

Go ahead and deploy a new empty service and set the needed service variables, this will be the server service.


ethancs13TRIAL

a year ago

Okay


ethancs13TRIAL

a year ago

Then what

Attachments


a year ago

  • Deploy the changes.

  • Generate a domain.

  • Set the root directory to /server


ethancs13TRIAL

a year ago

I think the servers are a little slow right now, it has been stuck on applying changes for awhile now.


a year ago

Yes, you can see the alert at the top of this page.


ethancs13TRIAL

a year ago

ok that part is done. Now what should i do next


ethancs13TRIAL

a year ago

I've ran the service but don't understand how to get the front end working now


a year ago

Please attach a screenshot of your project canvas.


ethancs13TRIAL

a year ago

Here is the log as well

Attachments


a year ago

Looks like you have both the frontend and the backend running? what seems to be the issue exactly?


ethancs13TRIAL

a year ago

This is the page

Attachments


a year ago

Ah gotcha, let me look at your repo.


a year ago

Aside from you having the build folder in the client I can't see anything wrong, I even deployed it myself and it works.

So make sure you don't have a build folder in GitHub and make sure it's in your .gitignore


ethancs13TRIAL

a year ago

oh, okay I gotcha. Thank you


ethancs13TRIAL

a year ago

Looks like the frontend and backend are working, but there seems to be an issue with the way I setup the CORS headers for railway. What should the client host be?

Attachments


ethancs13TRIAL

a year ago

Here is the console. The status code is 200 ok

Attachments


a year ago

As shown by those console logs, your frontend is trying to make requests to localhost, it needs to make requests to the backend domain.


ethancs13TRIAL

a year ago

ok with the port 3000? or just the link


a year ago

Just the link


ethancs13TRIAL

a year ago

I tried to change all my 'localhost:3001' axios requests to the endpoint and I think I broke something

Attachments



ethancs13TRIAL

a year ago

build logs

Attachments


a year ago

What version of node do you use locally?

Can you run npm run build locally?


ethancs13TRIAL

a year ago

heres the result. 21.1.0 node version

Attachments


a year ago

Set your engines.node to 21 in your package.json


ethancs13TRIAL

a year ago

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@fortawesome/fontawesome-free": "^6.5.2",
    "@mui/material": "^5.15.15",
    "@testing-library/jest-dom": "^5.17.0",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "axios": "^1.6.2",
    "bcrypt": "^5.1.1",
    "body-parser": "^1.20.2",
    "bootstrap": "^5.3.3",
    "cookie-parser": "^1.4.6",
    "cors": "^2.8.5",
    "crypto-browserify": "^3.12.0",
    "dayjs": "^1.11.11",
    "dotenv": "^16.4.5",
    "emotion": "^11.0.0",
    "install": "^0.13.0",
    "jsonwebtoken": "^9.0.2",
    "mysql": "^2.18.1",
    "npm": "^10.8.1",
    "os-browserify": "^0.3.0",
    "path-browserify": "^1.0.1",
    "react": "^18.2.0",
    "react-auth-kit": "^3.0.0-alpha.44",
    "react-bootstrap": "^2.10.2",
    "react-cookie": "^7.1.4",
    "react-country-state-city": "^1.1.0",
    "react-datepicker": "^7.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.20.1",
    "react-scripts": "^5.0.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
Here is my package.json. Where would I put that?

a year ago

As previously mentioned, Set engines.node to 21


ethancs13TRIAL

a year ago

should I do this in the root package.json?


ethancs13TRIAL

a year ago

the client one


ethancs13TRIAL

a year ago

or the client one*


a year ago

Yes of course the client's package.json, that is what we are talking about after all.


ethancs13TRIAL

a year ago

Okay, done.


a year ago

Commit the changes.


ethancs13TRIAL

a year ago

failed

Attachments


a year ago

You have not set your engines.node to 21


ethancs13TRIAL

a year ago

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    ...}
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "engines": {
    "node": "21"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
    ...]
  }
}


Like this?

a year ago

That's not a valid json file, you can just attach the file.


ethancs13TRIAL

a year ago

problem with the babel?

Attachments


a year ago

Set your engines.node to 20


ethancs13TRIAL

a year ago

looks like there are more babel errors about depreciation.

Attachments


a year ago

Try building your app locally with node 20.


ethancs13TRIAL

a year ago

seems to work fine


a year ago

Delete your node_modules folder and try again.


ethancs13TRIAL

a year ago

still seems fine


ethancs13TRIAL

a year ago

heres the log

Attachments


a year ago

Are you using node 20 locally now?


ethancs13TRIAL

a year ago

how do I revert to node 20. I am using the 21


a year ago

That would be out of the scope of this thread.


a year ago

I could reproduce the error locally with your project, running this command fixed it -

npm install @babel/plugin-proposal-private-property-in-object --save-dev

ethancs13TRIAL

a year ago

I will try that. Got node 20 installed

Attachments


ethancs13TRIAL

a year ago

Looks like its working! There was a CORS issue, but I resolved it.