0

How to deploy react (Create-React-App), Express.js and MySQL ?

I tried deploying on cPanel. do I have to change it to Production mode? how do I access the API on Express.js? do I have to create a sub domain on Express.js?

because so far I only use the library which is concurrently and nodemon. and on React.js I added a proxy like this: "proxy": "http: // localhost: 5000", where localhost: 5000 has a port from Express.js

Package.json script in server.js

  "scripts": {
    "client-install": "npm install --prefix client",
    "start": "node server.js",
    "server": "nodemon server.js",
    "client": "npm start --prefix client",
    "dev": "concurrently --kill-others \" npm run server\" \"npm run client\""
  },

Package.json script in React

  "proxy": "http://localhost:5000",
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

My App :

  • Client > folder react app > Package.json,Src
  • Node modules > npm from server
  • Server > Express config,Routes,Controller
  • .babelrc
  • server.js
  • package.json

1 Answer 1

0

Do you have terminal access on the cPanel? If yes, then

  1. Start your node server (Using PS or Nodemon)
  2. If your cPanel is using any kind of a server (nginx or Apache webserver for example), then configure the server file to redirect to localhost:5050 on *:80 and *:443
  3. Configure your Express.js to serve on port 5050

And that's it.

Sign up to request clarification or add additional context in comments.

9 Comments

yess i can use ssh using putty. so i dont need sub domain for get data from express.js? how can i configure *:80 and *:443 ?
You don't need a subdomain, by default the domain uses the *:80(HTTP) and *443(HTTPS) ports. You need to configure those in your server. Are you using Express js as your server (wherein you are serving the static files from the Express js app itself)?
i dont use static file in express.js. so how can i configure ?
How are you serving your react app to the users?
so the user can access react app with url localhost:3000
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.