// ssd vps

How to Install and Configure Node.js on a Linux VPS: Complete Guide for Modern Web Apps

August 26, 2026 · by Alex M.

How to Install and Configure Node.js on a Linux VPS: Complete Guide for Modern Web Apps

Node.js has become one of the most popular runtime environments for server-side development — from REST APIs and real-time applications to CLI tools and microservices. If you have a SSD VPS and want to run Node.js in production, this guide walks you through every step of the process.

Why Node.js Needs a VPS, Not Shared Hosting

Shared hosting is great for WordPress sites or classic PHP applications. However, Node.js requires its own persistent process, open ports and full control over the runtime environment — things that shared hosting cPanel doesn't natively support.

With an NVMe VPS, you get:
- Full root access — install any Node.js version you need
- Persistent processes — your app runs continuously via PM2 or systemd
- Predictable performance — no noisy neighbours
- Complete control over ports, firewall and configuration

Prerequisites

For this guide you will need:
- A VPS running Ubuntu 22.04 or Debian 12 (recommended)
- SSH access with root or sudo privileges
- Basic knowledge of the Linux command line

If you don't have a server yet, you can order an SSD VPS or a 1C VPS — affordable entry points for any new project.

NVM lets you install and switch between multiple Node.js versions without conflicts — the ideal approach for production environments.

Step 1: Install NVM

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Reload your shell configuration:

export NVM_DIR="$HOME/.nvm"
source ~/.bashrc

Verify the installation:

nvm --version
# output: 0.39.7

Step 2: Install Node.js LTS

nvm install --lts
nvm use --lts
nvm alias default 'lts/*'

Check the installed versions:

node --version
# v20.x.x
npm --version
# 10.x.x

Alternative Method: Install from NodeSource (System-Wide)

If you prefer a system-wide installation available to all users, use the official NodeSource repository:

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

This method is handy when using server management services where you need a standardised deployment across multiple environments.

Creating Your First Node.js Application

To test the environment, let's create a simple HTTP server:

mkdir ~/myapp && cd ~/myapp
nano app.js

Content of app.js:

const http = require('http');

const hostname = '0.0.0.0';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello from CliqHost VPS!\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Start the application:

node app.js

Open your browser and navigate to http://YOUR_VPS_IP:3000 — you should see the welcome message.

Process Management with PM2

In a production environment, your application must run continuously and restart automatically after a crash or server reboot. PM2 is the industry-standard solution.

Install PM2

npm install -g pm2

Start Your Application with PM2

cd ~/myapp
pm2 start app.js --name "myapp"

Configure Autostart on Reboot

pm2 startup
# Copy and execute the displayed command (with sudo)
pm2 save

Useful PM2 Commands

pm2 status          # check process status
pm2 logs myapp      # view application logs
pm2 restart myapp   # restart the app
pm2 stop myapp      # stop the app
pm2 delete myapp    # remove from PM2 list

Configuring Nginx as a Reverse Proxy

Your Node.js app listens on port 3000, but users access the site on ports 80/443. We configure Nginx to forward traffic correctly.

Install Nginx

sudo apt update
sudo apt install nginx -y

Set Up the Virtual Host

sudo nano /etc/nginx/sites-available/myapp
server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;

    location / {
        proxy_pass http://localhost:3000;
        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;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Enable the configuration:

sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Securing Your App with SSL

No modern site should run without HTTPS. Install Certbot for a free Let's Encrypt certificate:

sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

If you need a commercial SSL certificate with extended validation, CliqHost provides SSL certificates for all project types.

Firewall Configuration

Make sure necessary ports are open and port 3000 (internal) is not directly exposed to the internet:

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw deny 3000
sudo ufw enable
sudo ufw status

Using Environment Variables (.env)

Never hardcode credentials directly in your code. Use environment variables instead:

npm install dotenv

Create a .env file:

PORT=3000
DB_HOST=localhost
DB_USER=admin
DB_PASS=your_secret_password
NODE_ENV=production

At the top of app.js, add:

require('dotenv').config();
const port = process.env.PORT || 3000;

Important: Add .env to .gitignore to prevent sensitive data from being exposed.

Monitoring and Logs

PM2 stores application logs in ~/.pm2/logs/. View logs in real time:

pm2 logs myapp --lines 100

For deeper server resource monitoring, explore the articles on the CliqHost blog where you'll find guides on tracking CPU, RAM and disk usage on Linux.

Production Best Practices

  • Update regularly — keep Node.js and dependencies up to date (npm audit fix)
  • Restrict permissions — run Node.js as a non-root user
  • Configure rate limiting in Nginx to protect against DDoS attacks
  • Use cluster mode in PM2 to leverage all CPU cores:
pm2 start app.js -i max --name "myapp-cluster"
  • Implement health checks to detect issues early

Conclusion

Installing and configuring Node.js on a Linux VPS is straightforward when you follow the right steps. NVM gives you flexible version management, PM2 guarantees continuous application availability, and the Nginx + SSL combination completes a solid, secure production setup.

For the best performance, an NVMe VPS with ultra-fast storage makes a real difference when your Node.js application needs to handle tens or hundreds of concurrent requests. If you'd rather leave server administration to the experts, our server management services are here for you. Contact the CliqHost team and let's build something great together.

SHARE
// what clients say

What Our Clients Say

Real reviews from customers who trust CLIQHOST for performance, reliability and expert technical support.

★★★★★

"We moved our online shop from a foreign host and the difference is night and day — pages load instantly and support replies in minutes, in Romanian."

AM
Andrei M.
eCommerce owner · Chișinău
★★★★★

"Migrated 12 client sites to CLIQHOST. Free migration, zero downtime, and the cPanel setup is exactly what my team needed. Highly recommend."

EV
Elena V.
Web agency · Bălți
★★★★★

"Our NVMe VPS handles traffic spikes without a sweat. Full root, local datacenter, and billing in MDL — everything we wanted from a provider."

DC
Dmitri C.
SaaS founder · Chișinău