Node Js Application On Hosting Cloud

Let's first look at finished work. Click here

To demonstrate the whole procedure, I have created a subdomain where I will place all my node & react app files.

I'll use one of my Node React projects from GitHub. Here is the repo link if you want to check code.

react app github repo

Our React app resides in /client directory

Follow these simple steps to host node react app on web server

1. Go to your cPanel and search for Terminal

terminal in cpanel

2. In Terminal, type cd your_project_directory, for me it is cd and then git clone to clone the project

Note: Check in your File Manager, the project will be initialized into a separate folder,in my case MERN-product-app,open it and move all its content into root folder i.e

3. Now let's create script to run our node and react app Open package.json and add this script in scripts object "myScript": "concurrently --kill-others-on-fail \"npm run start\" \"cd client && npm install && npm run build\"",

react app package.json file

4. Now open cPanel and search Node and click on Setup Node.js App

5. Now click on Create Application, this brings a form and we need to populate it with some obvious values like, where our project files are and Application URL, Startup file, etc

creating node js app in web hosting
I have added MONGODB_URI in Environment Variable, as it is used by my application to connect to MongoDB

6. After that click on Run NPN Install

running NPM install

7. After that click Run JS Script, and click on myScript which you and I added before. On running this you will notice that react-scripts are not installed

react-scripts command not found

To fix this issue, we need to go to Terminal again, move into client directory, and install scripts one by one.

installing react react-scripts react-scripts command not found solved
Note: I first ran source /home /wanhrkzk /nodevenv / /10 /bin /activate && cd /home /wanhrkzk / to be able to run npm commands

8. Now Run myScript again and it will work fine.

9. Open your Application URL and Voila! Your app on the web, now pat yourself on the back

how to deploy node react app on web server gif

Thanks for reading! I hope you learned something useful.

Resource Link For more such related articles
Hosting reference: MilesWeb