Home > Software design >  I can't deploy my react nodejs application on the internet
I can't deploy my react nodejs application on the internet

Time:12-05

I have developed an application on React and NodeJs, everything works locally (localhost), but I do not understand how to deploy my application on the internet. Either on Cpanel (namecheap) or on netlify for example.

I tried different ways, I think my problem is either the organization of my files or the scripts in my package.json file.

Can someone tell me the best way to deploy my application on the internet? Thanks in advance

Three of my file

I have tried different ways of organizing my files, server part and client part in the same folder, server part and client part in separate folders, to modify the scripts calls in .json package

I tried to deploy in a private hosting on CPanel

All put in a zip, upload my files on mywebsite.com/myApp

extract files, setup a nodejs app, give the path, and start the npm and js script but it doesn't work ...

the only things i have is this is the result of my try to upload on CPanel

that's my package.json code : `

{
  "name": "react-node-app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node server/index.js",
    "build": "cd client && npm install && npm run build"
  },
  "engines": {
    "node": "16.14.2"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.20.1",
    "express": "^4.18.2",
    "n-readlines": "^1.0.1"
  }
}

`

CodePudding user response:

Step you can do before uploading your project reactjs to server:

  1. Build your apps using npm run build
  2. The build folder will generate after you successfully run build action
  3. upload your build folder to your server, and don't forget to point your domain to your folder correctly

Hope this help you :)

CodePudding user response:

I suggest you set up VM on a droplet(digital ocean) or Linode, allowing you to have your own web server. This way you can configure your nameserver in Namecheap to point to your droplet. Then use Nginx and Docker to run your NodeJs (backend) app. You can run a build of your React (frontend) app and then serve it from your web server. Use these links to help you setup:

  1. https://docs.digitalocean.com/products/droplets/how-to/create/
  2. https://github.com/evgeniy-khist/letsencrypt-docker-compose
  • Related