Run React project in a remote server and its configuration changes (CENTOS)

First, you need to update your server

for centos: yum update

for ubuntu: apt get update

Next step you need to install an updated node module(higher than 10)

For my case, I have installed a node version with 14

run :

sudo curl -sL | bash – in command line. (it includes the rpm file)

Then run:

sudo yum install nodejs

Now you need to check the node version by typing simply: node –version

Now it’s time to update npm.

type : sudo npm install -g npm-check-updates

After installation and update of the node and npm we need to create a test project now follow the below steps:

1.npx create-react-app reactapp

2. npm start (In your project directory)

3. After compiling your default test project is up and running on your local server with its default port 3000.

4. For accessing react project globally with domain name do some changes in package.json file.

first, modify your script sections start parameter

"start": " HOST=<domainname> PORT=3000 react-scripts start",

you can manually change the port number that you want by changing the port parameter.

white list your port in ip-tables by typing simply :

iptables -I INPUT -p tcp --dport <your port number> -j ACCEPT

5. Accessing your react app with HTTPS:

"start": "HTTPS=true SSL_CRT_FILE=<certificate.pem> SSL_KEY_FILE=<key.pem>HOST=<domain name> PORT=<your port number> react-scripts start",

for creation key and crt file run the commands:

openssl req -nodes -new -x509 -keyout server.key -out server.cert

now re-start your npm server.


Leave a Reply

Your email address will not be published. Required fields are marked *