DEV Community

Cover image for β›΄ Deploy React Apps In Production Pretty Easily 😎

β›΄ Deploy React Apps In Production Pretty Easily 😎

sudarshan on May 26, 2021

🍟 TL:DR : Serving react app is pretty simple if we does it directly through development environment( i.e. serve apps directly including ...
Collapse
 
01pooja profile image
Pooja G

Hey Sudarshan ,

I have a query.

I am unable to connect the dots here. Now I have the react front end project ready with build folder and Nodejs is installed on a Linux server . Now how can I deploy this react project on to nodejs? I wanted nodejs to serve both static and dynamic requests.

Collapse
 
sudarshansb143 profile image
sudarshan

nice question. So, when you create a build folder from react app then basically you end up with html, css and minified JS stuff. Now, for final deployment you will move this build folder to the Linux server and place it into the same directory as of your node.js server. Once done you can follow above article from Deployment Stuff

Hope it will be helpful

Collapse
 
01pooja profile image
Pooja G

Yes Sudarshan , this was the best article that I followed.

Collapse
 
cristianortiz profile image
Cristian Ortiz Navia

this is nice, this could work if a need to deploy a MERN app in a private server running other apps in LAMP?? there i need virtual host configs i think, but your setup could pull off this apache node deployment??

Collapse
 
sudarshansb143 profile image
sudarshan

sorry for delayed reply !

I don't have proper understanding of apache. But, I can assure you it would work with your other apps until it's port is available !

Hope this will be helpful

Collapse
 
radkriss profile image
radkriss

Hi Sudarshan,

I have a query.

  1. In development setup, we need to start the node server as well as the front end react app.

  2. For production setup, we have built the react front end and have those as static data in build folder. Start only the node server.

Is my understanding right ? Please clarify.

Collapse
 
sudarshansb143 profile image
sudarshan

You got that !

Because, we are serving the react build folder as the static asset of our nodejs backend πŸ˜ƒ

Collapse
 
radkriss profile image
radkriss

Thanks for the clarification, Sudarshan.

One query which has been in my mind for a long time is => "Why do we need a Nodejs server? If my React app is connecting to an external api (Java for eg) can't we have just the React front end ?"

Thread Thread
 
sudarshansb143 profile image
sudarshan

it's absolutely fine !

You can use node.js, django, spring / struts, rails or anything. But, you have to find a way to serve assets using that specific framework or technology

Collapse
 
vanhung1999dev profile image
HungNguyen

this is so simple...great..:

Collapse
 
rajeshkumaryadavdotcom profile image
Rajesh Kumar Yadav

This is super interesting