Skip to content
COL0

How to deploy a Node.js (Express) app on a VPS step by step

Your Node.js API answers on localhost:3000, but you close the terminal and it stops. This is what you need to keep it running all the time, with your domain and HTTPS.

Written by Victor Barrera

What you need before starting

  • A Linux server with SSH access and Node.js installed (use an LTS version).
  • Your code in a repository and a package.json with a start script.
  • A domain pointing to the server’s IP.

The steps, in short

  1. Secure the server: non-root user, SSH keys and a firewall open only on ports 22, 80 and 443.
  2. Clone the project and install dependencies with npm ci --omit=dev.
  3. Set the environment variables on the server (port, keys, database connection). Do not commit them to the repository.
  4. Keep the app alive with PM2 (pm2 start app.js and pm2 save) or a systemd service.
  5. Put Nginx in front as a reverse proxy to your app’s port.
  6. Enable HTTPS with Let’s Encrypt (certbot).
  7. Automate deploys: a GitHub Actions workflow that connects over SSH, runs git pull, installs and restarts.

Common mistakes

  • Listening on a different port than the one Nginx points to; check that the ports match.
  • Running npm install with NODE_ENV unset and ending up with dev dependencies in production.
  • Not handling uncaught errors: a single throw can take the process down.
  • Storing uploaded files inside the project and losing them on the next deploy.

How we help

We give you the free 30-minute diagnostic and leave your app running with automatic restarts, HTTPS, deploys from GitHub and alerts if something goes down.

Frequently asked questions

Should I use PM2 or systemd to keep my app running?

Both work. PM2 is easier to start with and offers basic logs and monitoring; systemd already ships with Linux and adds no dependencies. What matters is that the app restarts on its own if it fails or the server reboots.

Why do I need Nginx if Node already serves HTTP?

Nginx receives traffic on ports 80 and 443, handles the HTTPS certificate and forwards requests to your app. That way you do not run Node as an administrator or expose its port directly.

Ready to publish your project?

Book your free 30-minute session and leave with a clear plan.

Book your free session