In this article, we will learn how to deploy a react app to a node server. Most of the developers know about setup react applications but some of them have always confusion about the deployment of the react application on production servers. So in this article, I will give you a step by step explanation to deploy a react project.
There are some steps to deploy a react app to the node server.
Create react application
Now let’s create a react app using
create-react-app. Run the following command.
$ create-react-app first-app
Otherwise, you can follow Create React App.
Create server file
You will have to enter
first-app directory. Create a
server.js file with the following contents in the root directory.
Also, we will serve the application on 4
000 port. Make sure if you don’t have express installed in your system then install it.
Create a build of react application
Create a build of react application by running the following command.
$ npm run build
You can see the newly created
build folder in the root directory.
Use npm package to run the server continuously
At last, we are going to use the
forever npm package to run the server continuously.
Run the following command to install the package. Here we will globally install the package.
$ npm i forever -g
Now execute the following command to run the server continuously.
$ forever start server.js
After successful execution, you can check the link
That’s it for this time! I hope you enjoyed this post. As always, I welcome questions, notes, comments and requests for posts on topics you’d like to read. See you next time!