Docs / Programming & Development / Deploying a Node.js Application on Linux

Deploying a Node.js Application on Linux

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 31 views · 2 min read

Introduction

Node.js applications need a process manager and reverse proxy for production deployment. This guide covers the complete setup from installation to serving your app behind Nginx.

Install Node.js

# Using NodeSource repository (LTS version)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs

node --version
npm --version

Deploy Your Application

# Create app directory
sudo mkdir -p /var/www/myapp
cd /var/www/myapp

# Clone your repository
git clone https://github.com/you/myapp.git .
npm install --production

Process Manager with PM2

# Install PM2 globally
sudo npm install -g pm2

# Start your app
pm2 start app.js --name myapp

# Enable startup on boot
pm2 startup systemd
pm2 save

# Useful commands
pm2 list          # Show running apps
pm2 logs myapp    # View logs
pm2 restart myapp # Restart
pm2 monit         # Real-time monitoring

Nginx Reverse Proxy

server {
    listen 80;
    server_name example.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_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Environment Variables

Use a .env file and load it in PM2:

pm2 start app.js --name myapp --env production

Was this article helpful?