Template
Node.js Server
Node.js from nodejs.org, PM2 to keep apps running, and Nginx in front.
Steps, in order · version 1.0
Supported systems
Ubuntu 22.04+, Debian 12+, RHEL-compatible 8+ (AlmaLinux, Rocky Linux, RHEL, CentOS Stream, Oracle Linux), Amazon Linux 2023+. Still runs on Ubuntu 20.04 and Debian 11, which are past the end of standard support.
Options
As they appear on the run form, with their defaults.
Node.js version
One choice
- Node.js 24 (LTS)
- Node.js 22 (LTS, maintenance)
Default: Node.js 24 (LTS)
Install PM2
On or off
Default: On
Install Nginx
On or off
Default: On
What you get
A server ready for Node.js applications: Node.js from nodejs.org, checked against its published checksum, PM2 to keep applications running, and Nginx to put in front of them. The template does not deploy an application or configure a site.
Choosing the options
Node.js version: Node.js 24 (LTS) for new applications; Node.js 22 when a dependency does not support 24 yet.
Install PM2: keeps your applications running and restarts them if they crash. Leave it on unless you run applications as systemd services.
Install Nginx: to serve the application on ports 80 and 443 through a reverse proxy. Turn it off if another server or a load balancer sits in front.
What happens
- Update Packages.
- Install Node.js, with PM2 as a global package when chosen.
- Install Nginx, when chosen.
After the run
- Deploy the application and install its dependencies (
npm ci). - Start it with PM2, listening on a local port such as 3000:
pm2 start npm --name shop -- start, thenpm2 saveandpm2 startupso it starts again after a reboot. - Put HTTPS in front with Configure Reverse Proxy, forwarding to
http://127.0.0.1:3000. - Add a website monitor in Monitoring.
Common problems
- Node.js needs a newer glibc, or a command in /usr/local/bin was left alone: see Install Node.js.
- Port 80 is in use: see Install Nginx.