Table of Contents

Node.js - Getting Started Guide

Node.js is a JavaScript runtime for building server-side applications. This server comes with Node.js 24 LTS, npm, PM2 process manager, git and build-essential pre-installed. No setup wizard, no configuration – just SSH in and start deploying your applications.


Step 1 – Verify Node.js Works

Your server’s IP address and root password are shown in the Server Information section on the Overview tab of your server in the client portal. Connect to your server via SSH:

ssh root@your.server.ip

Verify that Node.js and PM2 are installed:

node --version
npm --version
pm2 --version

If you placed the server behind a VyOS router on a private network, the server has only a private address, so it does not get the IP certificate. Reach the server on the private address through a VPN on the router (WireGuard or OpenVPN, on the router’s Configuration tab), or forward ports 22, 80 and 443 to the server on the router’s Configuration tab (Port forwarding).


Step 2 – Deploy Your First Application

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

cd /root
git clone https://github.com/your-username/your-project.git
cd your-project
npm install

Step 3 – Set Up Reverse Proxy and SSL (Optional)

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

Then enable free HTTPS with Let’s Encrypt:

apt install -y certbot python3-certbot-nginx
certbot --nginx -d your-domain.com

Certbot will automatically configure SSL and set up auto-renewal.


PM2 – Process Manager

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 / stop / remove
pm2 restart myapp
pm2 stop myapp
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

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:

pm2 monit

Post-Installation

Fail2Ban – Brute-Force Protection

Your server comes with Fail2Ban pre-configured to protect SSH from brute-force attacks.

Rule Max Attempts Ban Duration
SSH5 failed logins10 minutes

Useful commands:

# Check banned IPs
fail2ban-client status sshd

# Unban an IP
fail2ban-client set sshd unbanip 1.2.3.4

If you accidentally lock yourself out, open the Console on your server’s Overview tab in the client portal and unban your IP.

Service Management

PM2 manages your Node.js apps. Nginx (if installed for reverse proxy) runs via systemd:

# PM2 daemon
pm2 resurrect              # restore saved process list
pm2 status                 # overview

# Nginx reverse proxy
systemctl status nginx
systemctl reload nginx
journalctl -u nginx -n 100

Native Modules

build-essential (gcc, g++, make) is pre-installed, so npm packages with native C/C++ addons compile without issues:

npm install bcrypt
npm install sharp
npm install sqlite3

npm 11 does not run install scripts of new packages until you approve them, and prints a warning such as “install scripts not yet covered by allowScripts”. Most popular native packages ship prebuilt binaries and work anyway. If a package fails to load after installation, approve its scripts and rebuild it: npm install-scripts approve package-name && npm rebuild package-name. The approval is saved in your project’s package.json.

Updates

# Update Node.js (within the 24.x line)
apt update && apt install -y nodejs

# Update PM2
npm install -g pm2
pm2 update

# Update OS packages
apt update && apt upgrade -y

Software Included

Component Version
Ubuntu24.04 LTS
Node.js24.x LTS (24.22)
npm11.19
PM27.1
git2.43
build-essentialgcc 13.3
Fail2Ban1.0.2

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 – you may need apt install python3 for some packages
No space left on device Check disk: df -h /. Clean npm cache: npm cache clean --force
Blocked by Fail2Ban Use the Console on your server’s Overview tab in the client portal to unban your IP
Forgot root password Use the Console on your server’s Overview tab in the client portal to reset it