Deploying a Node.js application requires a server that can run Node processes. BurjHost supports Node.js on specific plans (usually VPS or dedicated servers). This guide assumes you have a VPS.
Prerequisites:
-
A VPS with Node.js and npm installed.
-
Your application code ready (e.g., an Express.js app).
Step 1: Install Node.js (if not already installed)
Connect via SSH and install Node.js (example for Ubuntu/Debian):
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - sudo apt-get install -y nodejs
Verify: node -v and npm -v
Step 2: Upload Your Application
-
Use Git (clone your repository) or SCP/rsync to transfer your app files to the server.
-
Example using Git:
cd /var/www git clone https://github.com/yourusername/your-app.git cd your-app
Step 3: Install Dependencies
npm install
Step 4: Configure Environment Variables
Create a .env file or set environment variables as needed for your app.
Step 5: Run the Application (with Process Manager)
Use PM2 to keep your app running permanently:
npm install -g pm2 pm2 start app.js --name my-app # Replace app.js with your entry file pm2 startup # Ensures app restarts if server reboots pm2 save
Step 6: Set Up a Reverse Proxy (for Web Access)
To access your app via a domain (port 80/443), configure Apache or Nginx as a reverse proxy. For example, in Nginx:
server { listen 80; server_name yourdomain.com; location / { proxy_pass http://localhost:3000; # Your Node.js port 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; } }
Your Node.js app is now live!