Deploy a Node.js App to a Cloud VM

Get a Node.js app running in production on a cloud virtual machine — AWS EC2, DigitalOcean, or any Linux VM — behind Nginx and kept alive with a process manager.

intermediate25 minallUpdated August 2026
#deployment#nginx#linux#node.js

Requirements

  • A running Linux VM with a public IP (EC2, Droplet, etc.)
  • SSH access to the VM
0/5 steps · 0%
01

Connect and install Node.js

bash
$ ssh {{USERNAME}}@{{SERVER_IP}}

Note

Windows 10+ ships an OpenSSH client, so this works from PowerShell too — no extra tools needed.

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

Upload and install your app

bash
$ git clone {{REPO_URL}} app
$ cd app
$ npm ci --omit=dev

No repo on the server? rsync or scp a production build instead.

03

Keep it running with a process manager

bash
$ sudo npm install -g pm2
$ pm2 start npm --name app -- start
$ pm2 save
$ pm2 startup

Important

pm2 startup prints a command that needs sudo — run it as shown so the app also survives a server reboot.

04

Put Nginx in front of it

/etc/nginx/sites-available/app
server {
listen 80;
server_name {{DOMAIN}};
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;
}
}
bash
$ sudo ln -s /etc/nginx/sites-available/app /etc/nginx/sites-enabled/
$ sudo nginx -t && sudo systemctl reload nginx
05

Open the firewall

bash
$ sudo ufw allow OpenSSH
$ sudo ufw allow 'Nginx Full'
$ sudo ufw enable

Success

Visiting http://{{DOMAIN}} now serves your app through Nginx.

Troubleshooting

Nginx is reachable, but the app it's proxying to isn't running or isn't listening on the port Nginx expects.

bash
$ pm2 status
$ pm2 logs app