Node.js VPS - Getting Started Guide
Your Node.js VPS based on Ubuntu 24.04 is ready to go - Node.js, npm and PM2 process manager are already installed. No setup wizard, no configuration - just SSH in and start deploying your applications.
Software Included
| Component | Version |
|---|---|
| Ubuntu | 24.04 LTS |
| Node.js | 22.x LTS |
| npm | 10.x |
| PM2 | 6.x |
| git | 2.43 |
| build-essential | gcc 13.3 |
| Fail2Ban | 1.0.2 |
Prerequisites
Before you begin, make sure you have:
- An SSH client (Terminal on macOS/Linux, or PuTTY on Windows)
Step 1 - Get Your Server Credentials
Log in to your client panel and open your VPS service details. You will need:
- IP address of your server
- Root password
Step 2 - Connect via SSH
Open your terminal and connect to the server:
ssh root@your.server.ip
Enter the root password from your client panel when prompted.
Step 3 - Verify Installation
Check that Node.js and PM2 are installed:
node --version
npm --version
pm2 --version
Deploying Your Application
Quick Start - Hello World
Create a simple HTTP server to test that everything works:
mkdir ~/myapp && cd ~/myapp
cat > app.js << 'EOF'
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello from Node.js ' + process.version + '\n');
});
server.listen(3000, () => console.log('Server running on port 3000'));
EOF
node app.js
Open http://your.server.ip:3000 in your browser. You should see the greeting message. Press Ctrl+C to stop the server.
Deploy from Git Repository
Clone your project and install dependencies:
cd /root
git clone https://github.com/your-username/your-project.git
cd your-project
npm install
PM2 - Process Manager
Why PM2?
Running node app.js directly stops the app when you close the terminal or if it crashes. PM2 keeps your application running in the background, restarts it on crash, and auto-starts it after server reboot.
Basic Commands
# Start your application
pm2 start app.js --name myapp
# View running applications
pm2 list
# View logs
pm2 logs myapp
# Restart application
pm2 restart myapp
# Stop application
pm2 stop myapp
# Remove application from PM2
pm2 delete myapp
Auto-Start on Reboot
PM2 is pre-configured to start on boot. After starting your apps, save the process list so they restart automatically after a server reboot:
pm2 save
Run pm2 save again whenever you add or remove applications.
Cluster Mode
PM2 can run multiple instances of your app to use all available CPU cores:
# Start with one instance per CPU core
pm2 start app.js -i max --name myapp
# Or specify the number of instances
pm2 start app.js -i 2 --name myapp
Monitoring
View real-time CPU and memory usage for your applications:
pm2 monit
Press Ctrl+C to exit the monitor.
Post-Installation
Installing Packages
build-essential (gcc, g++, make) is pre-installed, so npm packages with native C/C++ addons will compile without issues:
npm install bcrypt
npm install sharp
npm install sqlite3
Setting Up a Reverse Proxy
To serve your app on port 80/443 with a domain name, install Nginx as a reverse proxy:
apt update && apt install -y nginx
cat > /etc/nginx/sites-available/myapp << 'EOF'
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;
}
}
EOF
ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default
nginx -t && systemctl reload nginx
SSL with Let's Encrypt
After setting up Nginx with your domain, enable free HTTPS:
apt install -y certbot python3-certbot-nginx
certbot --nginx -d your-domain.com
Certbot will automatically configure SSL and set up auto-renewal.
Fail2Ban - Brute-Force Protection
Your server comes with Fail2Ban pre-configured to protect SSH from brute-force attacks. After 5 failed login attempts, the IP is banned for 10 minutes.
Updates
To update Node.js to the latest LTS version:
# Update Node.js
apt update && apt install -y nodejs
# Update PM2
npm install -g pm2
pm2 update
# Update OS packages
apt update && apt upgrade -y
Troubleshooting
| Problem | Solution |
|---|---|
| App crashes and doesn't restart | Use PM2 instead of node app.js: pm2 start app.js |
| App not running after reboot | Run pm2 save after starting your apps to enable auto-start |
| Port already in use | Check what's using it: ss -tlnp | grep :3000 |
npm install fails with build errors |
build-essential is pre-installed. Check the error message - you may need apt install python3 for some packages |
| ENOSPC: no space left on device | Check disk usage with df -h /. Clean npm cache: npm cache clean --force |
| Forgot root password | Use VNC console in your client panel to reset it |