@noemy.bosco
To run a React.js app on Vultr, you can follow these steps:
- Deploy a Vultr server: Sign up for Vultr and deploy a server of your choice (e.g., Ubuntu, CentOS, or Debian).
- Connect to your server: Access your server via SSH using a terminal or an SSH client like PuTTY.
- Install Node.js: Update the package manager index and install Node.js on your server by running the following commands:
sudo apt update
sudo apt install nodejs
- Install npm: Npm is the package manager for Node.js. Install npm by executing this command:
sudo apt install npm
- Clone your React.js app: Clone your React.js app repository from your version control system (e.g., Git) to your server. You can use the git clone command to clone the repository.
- Install dependencies: Navigate to the root directory of your React.js app, where the package.json file is located, and run the following command to install the app dependencies:
npm install
- Build your React app: Once the dependencies are installed, build your React app by running the below command:
npm run build
- Install a web server: To serve your React app, you can use a web server like Nginx. Install Nginx by executing the following command:
sudo apt install nginx
- Configure Nginx: Edit the default Nginx configuration file by running the command:
sudo nano /etc/nginx/sites-available/default
Replace the contents of the file with the following configuration:
server {
listen 80;
server_name your-domain.com;
root /path/to/your/react-app/build;
location / {
try_files $uri /index.html;
}
}
Replace your-domain.com with your domain name or server IP address, and /path/to/your/react-app/build with the actual path to your React app's build folder.
- Save and close the file by pressing Ctrl + X, then Y, and finally hitting Enter.
- Start Nginx: Start the Nginx server by executing this command:
sudo systemctl start nginx
- Enable Nginx on boot (optional): If you would like Nginx to start automatically when the server boots up, run the following command:
sudo systemctl enable nginx
- Access your React app: Now, you should be able to access your React app by navigating to your server's IP address or domain name in a web browser.
That's it! You have successfully run a React.js app on Vultr using Nginx as the web server.