- Ensure all dependencies are installed:
npm install
- Build the application for production:
npm run build
- Connect to the VPS:
ssh user@your_vps_ip
- Update the package manager:
sudo apt update && sudo apt upgrade -y
- Install Node.js and npm:
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - sudo apt install -y nodejs
- Install Nginx:
sudo apt install -y nginx
- Transfer application files to the VPS (using SCP or any other method):
scp -r . user@your_vps_ip:/path/to/your/app
- Navigate to the application directory:
cd /path/to/your/app
- Install production dependencies:
npm install --production
- Create a new Nginx configuration file:
sudo nano /etc/nginx/sites-available/your_app
- Add the following configuration:
server { listen 80; server_name your_domain_or_ip; location / { proxy_pass http://localhost:3000; # Adjust the port if necessary proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }
- Enable the configuration:
sudo ln -s /etc/nginx/sites-available/your_app /etc/nginx/sites-enabled/
- Test the Nginx configuration:
sudo nginx -t
- Restart Nginx:
sudo systemctl restart nginx
- Create a
.env
file in the application directory and add necessary environment variables.
- Use a process manager like PM2 to run the application:
npm install -g pm2 pm2 start npm --name "your_app_name" -- run start pm2 startup pm2 save
- Open your browser and navigate to
http://your_domain_or_ip
to verify that the application is running correctly.
- Ensure that your firewall allows traffic on port 80 (HTTP) and 443 (HTTPS if using SSL).
- Consider setting up SSL using Let's Encrypt for secure connections.