How to deploy a Node.js app to production
Updated 10/16/2026
Running node app.js in a terminal does not keep the app alive after you disconnect. Here is how to deploy it properly, with auto-restart and an HTTPS domain.
1. Install Node.js
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
2. Run the app with PM2
PM2 keeps the app running and restarts it if it stops:
npm install -g pm2
cd /var/www/app
pm2 start app.js --name my-app
pm2 startup
pm2 save
3. Put Nginx in front
The app listens on an internal port (e.g. 3000); Nginx receives public traffic. See How to set up Nginx as a reverse proxy.
4. Add HTTPS
See Free SSL certificate with Let's Encrypt.
Useful PM2 commands
pm2 list
pm2 logs my-app
pm2 restart my-appPut this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
How to deploy a Laravel app to production
Deploy Laravel properly on a VPS: Nginx, PHP-FPM, permissions, optimizations and the queue worker.
Updated 10/16/2026Web serversHow to optimize Nginx performance: gzip, cache and HTTP/2
Make your site faster with gzip compression, static file caching and HTTP/2, a few lines of config.
Updated 10/16/2026Web serversHow to force HTTPS and redirect HTTP
After installing SSL, make sure every visitor uses HTTPS, with a permanent 301 redirect from HTTP.
Updated 10/16/2026