Running Node.js Projects in Production with PM2: Panel Guide
To put your Node.js and Express projects into production on VPS, set PM2 cluster mode, automatic restart, memory limit and log rotation settings on the panel.
#node.js
#pm2
#deploy
#express
#nestjs
VDS Panel Ekibi
Ürünü geliştiren ekip
~8 dk
okuma
deployment
kategori
Node.js is a runtime that works with an event loop on a single thread. This architecture has tremendous performance for API servers, but it has two limits: if there is a crash, the process dies, it does not work in parallel as many CPU cores. PM2 is a process manager designed to overcome these two limits. It is one of the leading tools used for Production Node.js deployment.
In this guide, we will explain what PM2 does in production, which settings you care about and why, and how you can manage these settings from the interface with VDS Panel.
Bir bakışta
99.9%
Uptime target
4-8×
throughput with cluster
<1sec
automatic restart
0
Downtime reload
What does PM2 do?
PM2 “daemonises” your Node.js processes. Well:
Restarts the process when it crashes
Opens more than one process and distributes the load (cluster mode)
Writes the logs to the file and rotates them
Manages uninterrupted traffic between restarts
Monitors Memory/CPU, restarts process that exceeds limits
It is also possible to run Node.js with systemd, but you need to install the above features one by one.
Why is cluster mode important?
Node.js runs single thread by default. If you are running a Node process on a 4-core VPS, your 75% CPU capacity remains idle. PM2 cluster mode opens as many worker processes as there are CPU cores and distributes the load among them:
P0
4-8×
more throughput
Cluster mode compared to single instance mode on 4-core VPS.
Link or ZIP the GitHub repository. The panel detects package.json, uses 'scripts.start' or the entry point you specify.
02
Set up cluster
Slider for number of instances: 1 (fork mode) to the number of CPUs of your VPS. For most APIs, 2-4 is ideal.
03
Set memory limit
Like 256MB, 512MB, 1GB. The worker exceeding this limit will automatically restart. Memory leak is tolerated, the app continues to work.
04
Enter env variables
NODE_ENV=production, DATABASE_URL, API keys. It is not written to Git, it is stored in the panel secret vault and injected at runtime.
05
Connect domain
Custom domain name or subdomain. The panel automatically obtains the Let's Encrypt certificate and directs the nginx reverse proxy to your 3000 port.
06
Press Deploy
Your app is live in ~90 seconds. When you do a git push, zero-downtime reload is triggered.
Zero-downtime reload
One of PM2’s most powerful features is graceful reload. When you deploy new code:
PM2 starts new workers
New workers start listening
Waits for old workers to finish their current requests (graceful shutdown)
Old workers close down
The user does not feel any interruption. VDS Panel makes every deployment with this strategy.
Graceful shutdown signal
If your Node.js application is listening for the SIGINT or SIGTERM signal, when PM2 is shutting down, it gives your application 10 seconds to perform cleaning tasks such as closing open DB connections and flushing the cache. The panel sets this time by default.
Defense against memory leaks
Node.js memory leaks are common; especially when the event listener is forgotten and the global cache grows. The P0 setting of PM2 provides the solution:
P1
In the panel interface, this value is a slider. If you specified 512M, PM2 silently restarts a worker when it exceeds 512MB. Other workers continue to handle traffic.
DEV dependencies in Production
It installs with panel P0, dev dependencies are not installed. If you import a package in P1 at runtime, the production build will fail. You will see these errors in the panel build log.
Log management
PM2 writes P0 and P1 for each worker. Over time, these files become full. The panel automatically activates log rotation:
Rotate when file size reaches 100 MB
5 old files are kept
Logs are streamed live from the panel UI (without opening a terminal)
Monitoring and alerts
For each PM2 process, the panel:
CPU and memory graph flows live
Number of restarts is monitored (too many restarts = bug signal)
Response time telemetry (if express-status-monitor or similar is added)
Automatic cpulimit daemon launch when CPU limit is exceeded (protecting neighboring projects)
Node.js frameworks
VDS Panel has been tested with and automatically detects the following frameworks:
The panel reads your P0, detects the correct framework, and selects the appropriate start script.
Conclusion
PM2 is a must for Node.js production. Cluster mode, automatic restart, memory limit, log rotation, zero-downtime reload, all come with a single daemon. VDS Panel allows you to manage these settings from the interface without memorizing the terminal command.
To get your Node.js project live, you can complete the panel setup in 8 minutes and see your first project by requesting a demo from our contact form.