Guides ยท Sep 27, 2026
How to Deploy a Node.js App with PM2, Nginx and Free SSL
Deploy an Express or Next.js app to a Linux VPS: install Node.js, keep it running with PM2, put Nginx in front and add a free Let's Encrypt certificate.
This is the classic production setup for Node.js: PM2 keeps the app alive, Nginx handles HTTPS and forwards traffic to it. Point your domain's A record at your server first.
1. Install Node.js and PM2
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs nginx
sudo npm install -g pm2
2. Start your app
git clone https://github.com/you/your-app.git && cd your-app
npm ci
npm run build # if your app has a build step (Next.js, TypeScript)
PORT=3000 pm2 start npm --name web -- start
pm2 save && pm2 startup # run the printed command so it survives reboots
Check it with curl localhost:3000.
3. Put Nginx in front
Create /etc/nginx/sites-available/web:
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-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
sudo ln -s /etc/nginx/sites-available/web /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo ufw allow 'Nginx Full'
4. Free HTTPS
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com
5. Deploying updates
git pull && npm ci && npm run build && pm2 reload web
pm2 reload restarts without dropping connections.
Need a server for this?
Every TidalVPS VPS comes with full root access, unmetered traffic, daily backups and DDoS protection.