How to deploy a react app to node server

React + Express

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.

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.

You will have to enter first-app directory. Create a server.js file with the following contents in the root directory.

File Structure

Also, we will serve the application on 4000 port. Make sure if you don’t have express installed in your system then install it.

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.

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 http://localhost:3000/ .

Default React App

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!

I’m a MERN Developer. ( Redux | AWS | Python ) I enjoy taking on new things, building skills, and sharing what I’ve learned.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store