nvm install --lts, then install PM2 with npm install -g pm2. Start your app with pm2 start app.js --name myapp, run pm2 save, then run pm2 startup and paste the sudo command it prints. PM2 now restarts your app if it crashes and starts it again after a reboot. Put Nginx in front for your domain and HTTPS.
Before you start
- Work as a normal user, not
root, so your app does not run with full system rights. See create a sudo user. This guide uses the useralex. - Pick an LTS (long-term support) release of Node.js for servers. Today the LTS lines are 26, 24 and 22. Node.js 26 is the newest LTS.
How to install Node.js
- nvm (recommended, any distro)
- NodeSource (system-wide)
nvm installs Node.js in your home folder, so you need no
sudo and can switch versions easily.nvm install --lts installs the newest LTS release. To pin a line, use for example nvm install 24.apt install nodejs) is often older than the current LTS. Check it with apt-cache policy nodejs before you rely on it.
How to install PM2 and start your app
1
Install PM2
sudo npm install -g pm2.2
Start your app
From your app’s folder:For an app started with
npm start, use pm2 start npm --name myapp -- start.3
Save the process list
~/.pm2/dump.pm2 and restores it at boot.4
Start PM2 at boot
sudo env PATH=$PATH:…. Copy and run that exact command. It creates a systemd service named pm2-alex.How to check it worked
online (output shortened):
curl http://127.0.0.1:3000. Reboot the server once to confirm the app comes back by itself.
Everyday PM2 commands
For several apps or environment variables, create a config file with
pm2 init simple. It writes ecosystem.config.js, which you start with pm2 start ecosystem.config.js.
How to put your app online with Nginx
Keep the app listening on127.0.0.1, not on a public port. Then add an Nginx reverse proxy for your domain and HTTPS. See set up Nginx as a reverse proxy.
Frequently asked questions
My app stops when I close the SSH window. Why?
You started it withnode app.js in the terminal. Start it with PM2 instead, or use tmux or screen for quick tests only.
After a reboot my app is gone. What did I miss?
Eitherpm2 save was not run after starting the app, or the sudo env PATH=… command from pm2 startup was not run. Do both again.
How do I upgrade Node.js?
Install the new version (nvm install --lts), then refresh PM2’s boot script: run pm2 unstartup and the command it prints, then pm2 startup and the command it prints, and finally pm2 save.
Can I use systemd instead of PM2?
Yes. A plain systemd service also restarts your app and starts it at boot. See create a systemd service.Related guides
VPS and dedicated server guides
Every server guide in one place.
Nginx reverse proxy
Domain and HTTPS for your app.
Host a Discord bot
A common Node.js use.
Create a systemd service
The alternative to PM2.
Fix 502 Bad Gateway
When Nginx can’t reach the app.
Checked against the official Node.js releases page, the nvm README and the PM2 startup documentation on 4 November 2026; PM2 7.1.2 commands (
start, save, startup, init simple) tested on Ubuntu 24.04 LTS with Node.js 22. nvm and NodeSource installs were not tested. Commands can differ on other distributions or releases.Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026