How to Deploy Node.js Apps on a VPS

PM2, Nginx and HTTPS are preinstalled on DreamHost's image. Here's what remains your job.

Illustration of a step-by-step guide with completed steps
On this page
  1. What this setup does and who needs it
  2. What DreamHost's Node.js VPS provides
  3. Keeping apps running
  4. Deployment considerations
  5. Security and maintenance
  6. Is DreamHost's offering suitable?
  7. Alternatives
  8. Frequently asked questions
  9. Sources

A VPS is a common home for Node.js applications that need to run all the time. DreamHost's image preinstalls the usual pieces, and you remain responsible for your code and the server.

What this setup does and who needs it

Our explanation Developers who've outgrown simple hosting often use a VPS for APIs and web apps. A process manager keeps the app running, and a reverse proxy handles HTTPS traffic in front of it.

What DreamHost's Node.js VPS provides

Officially documented DreamHost's Node.js page lists Node.js, the PM2 process manager, Nginx as a reverse proxy and Certbot for SSL. You push your code, start it with PM2 and serve it through Nginx. The page doesn't state the Node.js version or how code should be pushed. PostgreSQL is listed as a separate app in the library, and the page doesn't say it's preinstalled here.

DreamHost's Node.js image includes PM2, Nginx and Certbot.

View Node.js VPS Plans (opens DreamHost: Node.js Hosting in a new tab)

Keeping apps running

Officially documented PM2's documentation explains restarting after a reboot: run pm2 startup, run the command it prints, start your apps, then run pm2 save. After upgrading Node.js, run pm2 unstartup and pm2 startup again so the script points to the new binary.

Deployment considerations

Our explanation Keep secrets in environment variables, away from your code repository. Check your Node.js version against your app's needs. Decide how you'll deploy, such as with Git, and how you'll roll back. Write logs somewhere you can read them, and rotate them so they don't fill the disk.

Security and maintenance

Our explanation Update Node.js, your dependencies and the operating system regularly. Run the app as a non-root user, and expose it only through the reverse proxy. Back up your database and any uploaded files, since code alone won't restore a live app.

The everyday work is the same for any self-managed server, so we cover patching, firewalls, logins and backups in what managing a VPS involves.

Is DreamHost's offering suitable?

Our explanation It suits developers who want a ready runtime and full control. If you don't want to manage a server, DreamHost's Managed VPS lists Node.js support without root access, so check that your app runs within those limits.

Alternatives

Frequently asked questions

How do I keep a Node.js app running after a reboot?

PM2's documentation describes using pm2 startup and pm2 save.

Does DreamHost support my Node.js code?

On its self-managed VPS, support covers hardware, network and connectivity. The page doesn't describe help with your code.

Sources

  1. DreamHost: Node.js VPS
  2. PM2 Docs: Startup script