Logo

How to Deploy a react app using PM2 on Ubuntu Server 23.04

Dec 02, 2023

To deploy a React app on Ubuntu Server 23.04 using PM2, follow the steps below.

Step 1 : Install PM2

Begin by installing PM2 globally using npm.

npm install -g pm2

Step 2 : Run PM2 startup

Set up PM2 to start on boot.

pm2 startup

Step 3 : Create a React app

Use Create React App to generate a new React application.

npx create-react-app my-react-app

Step 4 : Build the app

Navigate to the app's directory and build the project.

cd my-react-app
npm run build

Step 5 : Run the app with PM2

Serve the built files using PM2, specifying the port and app name.

pm2 serve build/ 3000 --name "my-react-app" --spa

Step 6 : Test the app

Open your browser and navigate to your server's IP address or domain to test the deployed React app.

Step 7 : Manage the Application

- Check the application status:

pm2 status

- Restart the application:

pm2 restart my-react-app

- Reload the application without downtime:

pm2 reload my-react-app

- Stop the application:

pm2 stop my-react-app

- Delete the application from PM2:

pm2 delete my-react-app

Congratulations! You have successfully deployed a React app on Ubuntu Server 23.04 using PM2.

Recommended