Using PM2 to Monitor n8n Processes (Step-by-Step)

Using PM2 to Monitor n8n Processes (Step-by-Step)

Using PM2 to Monitor n8n Processes (Step-by-Step) blog

Running n8n without a process manager is like driving without seatbelts. It works fine until it doesn’t. One server hiccup, one closed terminal, one unexpected crash, and your workflows disappear.

This step-by-step guide shows you exactly how to use PM2 for persistent, monitored n8n deployments that recover automatically from any failure.

Monitoring n8n with PM2 requires a VPS that delivers stable performance and reliable process management support. The comparison table below highlights VPS hosting providers that handle long running automation workloads efficiently. These providers make it easier to monitor uptime, restart processes automatically, and maintain workflow stability. Explore our recommended VPS hosting options.

VPS Hosting Providers Optimized for Monitoring and Managing n8n Processes

ProviderUser RatingRecommended For 
Kamatera Logo4.8ScalabilityVisit Kamatera
4.6AffordabilityVisit Hostinger
4.7DevelopersVisit IONOS

Takeaways
  • PM2 keeps n8n running in the background, surviving terminal closures and server reboots.
  • Install Node.js version 14.15 or higher before setting up PM2 or n8n.
  • Ecosystem config files centralize all deployment settings in one version-controllable location.
  • Memory-based restarts prevent out-of-memory crashes during heavy workflow executions.
  • PostgreSQL outperforms SQLite for production deployments with concurrent access.
  • SSL/TLS encryption through Nginx protects credentials and webhook traffic.

Why You Should Be Using PM2 to Monitor n8n Processes

PM2 is a production ready process manager for Node.js applications with over 100 million downloads. That’s not a typo. It’s become the default choice for developers who need their applications running 24/7 without babysitting.

Here’s what makes it essential for n8n deployments:

  • Automatic recovery: Your workflows restart after crashes without intervention.
  • Boot persistence: The n8n service starts automatically when your server reboots.
  • Environment variable management: Centralized configuration for scalable automation.
  • Resource monitoring: Real-time CPU and memory tracking at your fingertips.

Without PM2, closing your terminal kills your running n8n instance. With it, your automation tools keep working whether you’re watching or not.

A Developer Friendly Alternative to Docker Compose

Docker Compose works great for complex microservice architectures. But for straightforward n8n deployments? It’s often overkill.

PM2 operates at a different layer than containerization. It manages your application lifecycle directly within the operating system. No container networking. No image builds. No orchestration headaches.

Teams that prefer single-server deployments love PM2 because it handles scaling efficiently without the steep learning curve. You get full control over your processes without needing container expertise.

For a deeper comparison, check our guide on Docker Compose vs Bare-Metal VPS to understand when each approach makes sense.

Bypassing the Need to Install Docker

Small to medium deployments don’t need containerization overhead. Docker adds infrastructure complexity that PM2 eliminates entirely.

The resource savings matter, especially on VPS environments. You’re not running a container runtime consuming RAM that could power your workflows instead. This makes PM2 highly cost-effective for teams seeking cheap n8n hosting solutions.

If you want to install Docker later for other projects, nothing stops you. But for running n8n reliably? PM2 handles everything you need.

Preparing for Your n8n Installation

Step 1: How to Install Node.js

Node.js website.

Before anything else, your server needs Node.js and npm installed. The n8n installation requires Node.js version 14.15 or higher.

Start by updating your system packages:

sudo apt update

Pro Tip: Use Node Version Manager to manage multiple Node.js versions. It prevents system conflicts and lets you switch versions instantly. Install it, then run:

nvm install 18
nvm use 18

This approach gives you flexibility when different projects need different node versions.

Step 2: How to Install PM2

With Node.js active, install PM2 globally using npm:

sudo npm install -g pm2

The above command makes PM2 accessible system-wide. Any user can execute PM2 commands from anywhere on your server.

Verify the installation worked:

pm2 –version

You should see a version number. If not, check your npm permissions.

Step 3: How to Install n8n Globally for the Latest Version

Installing n8n globally is the recommended approach for process manager deployments. Run:

npm install -g n8n

This suggested command installs the latest version of n8n and makes it available system-wide. PM2 can easily locate the executable when you start access to your automation platform.

Once installed, start n8n manually to verify it works:

n8n start

The web interface becomes accessible via localhost:5678 on your local machine or IP_ADDRESS:5678 on a server. Stop it with Ctrl+C once you’ve confirmed it’s working.

Setting Up the n8n Service with PM2

Creating Your First Configuration File

Ecosystem configuration files provide a declarative way to manage your n8n instance. Create a file called ecosystem.config.js:

module.exports = {
  apps: [{
    name: ‘n8n’,
    script: ‘n8n’,
    args: ‘start’,
    autorestart: true,
    max_memory_restart: ‘300M’,
    env: {
      EXECUTIONS_DATA_PRUNE: ‘true’,
      EXECUTIONS_DATA_MAX_AGE: ‘168’,
      DB_SQLITE_VACUUM_ON_STARTUP: ‘true’,
      N8N_BASIC_AUTH_ACTIVE: ‘true’,
      N8N_BASIC_AUTH_USER: ‘admin’,
      N8N_BASIC_AUTH_PASSWORD: ‘your-secure-password’,
      GENERIC_TIMEZONE: ‘America/New_York’
    }
  }]
};

This config file centralizes all deployment settings. You can manage multiple applications simultaneously and track changes through version control.

Key production settings explained:

  • EXECUTIONS_DATA_PRUNE: true removes old execution data automatically.
  • EXECUTIONS_DATA_MAX_AGE: 168 retains data for one week.
  • autorestart: true ensures recovery after crashes.

Managing Environment Variables Securely

PM2 launches n8n in fork mode, keeping the workflow engine running.

Ecosystem files let you set environment variables that override default configurations. Essential variables include authentication settings, timezone configuration, and database connections.

Security Note: Never commit sensitive variables to version control. Use secure configuration management practices. Rotate production credentials regularly.

For advanced configurations involving secrets, consider using environment-specific config files or external secret managers.

Launching Your n8n Instance

Start your n8n with PM2 using the following command:

pm2 start ecosystem.config.js –update-env

The –update-env flag ensures environment variables apply correctly. Without it, PM2 might use cached values from previous runs.

Save your configuration to survive reboots:

pm2 save

Then configure the startup script:

pm2 startup

This command asks you to run a specific sudo systemctl command. Copy and execute it. Your n8n instance now starts automatically after server reboots.

Ultahost

Launch, Scale, and Manage your website with high-performance Web Hosting and VPS.
Visit Site Coupons6

Comprehensive Monitoring Capabilities

Real-Time Resource Tracking

The pm2 monit command opens a live terminal dashboard. You’ll see CPU usage, memory consumption, and process status updating in real-time.

Monitoring MetricPurposeUse CaseUpdate Frequency
CPU UsageTrack processor utilizationIdentify CPU-intensive workflowsReal-time
Memory ConsumptionMonitor RAM usagePrevent out-of-memory crashesReal-time
Process StatusVerify running/stopped stateConfirm operational statusReal-time
UptimeTrack continuous operationDetect excessive restartsReal-time
Restart CountMonitor process stabilityIdentify recurring crashesReal-time
Process ID (PID)Identify process instanceDebug and troubleshootOn status change

Check your process list anytime:

pm2 list

This shows all managed processes with their current status, memory usage, and restart counts.

Memory-Based Monitoring and Thresholds

Workflow executions consume substantial memory when processing large datasets. Think Google Sheets imports with thousands of rows or AI agents analyzing documents.

The max_memory_restart option lets you specify limits:

max_memory_restart: ‘300M’

PM2’s internal memory monitoring checks every 30 seconds. Restarts won’t be instantaneous when thresholds are exceeded, but they prevent catastrophic failures.

For deeper performance tuning, explore our guide on optimizing Node.js memory for n8n deployments.

Advanced Logging and Health Checks

Real-Time Log Streaming and Rotation

PM2 stores separate output and error logs in $HOME/.pm2/logs by default. Stream logs in real-time:

pm2 logs n8n

Add –lines 50 to view only recent events.

For log management at scale, install pm2-logrotate:

pm2 install pm2-logrotate

This automatically generate compressed archives of older logs, saving disk space.

Control n8n’s internal logging with the N8N_LOG_LEVEL variable. Options include silent, error, warn, info, and debug.

Verifying System Readiness

Health endpoints help external monitoring tools verify your instance is running:

  • /healthz returns HTTP 200 when reachable.
  • /healthz/readiness confirms active database connections and completed migrations.

Enable the N8N_METRICS variable to expose granular performance data for tools like Prometheus.

Prometheus website.

Restart Strategies and System Resilience

Automatic and Exponential Backoff Restarts

PM2 offers multiple restart strategies for different failure scenarios:

Restart StrategyPurposeConfigurationBest Use Case
Automatic RestartRecovery from crashesDefault behaviorAll deployments
Memory-Based RestartReclaim memory leaksmax_memory_restart: “300M”High-volume workflows
Cron-Based RestartScheduled maintenancecron_restart: “0 2 * * *”Daily resets
Exponential BackoffHandle cascading failuresexp_backoff_restart_delay: 100External dependency issues
Watch-Based RestartDevelopment iterationwatch: trueDevelopment only

Use stop_exit_codes: [0] to skip automatic restarts for intentional shutdowns.

Zero-Downtime Reloads

Production environments need updates without dropping webhook requests. Use PM2 restart n8n with the reload command:

pm2 reload n8n

This performs zero-downtime reloads by sequentially restarting instances. Applications must handle SIGINT signals for graceful shutdowns.

Scaling with Cluster Mode

Maximizing CPU Utilization

Node.js runs single-threaded by default. Multi-core servers sit mostly idle. Fix this with cluster mode:

instances: ‘max’

PM2 spawns one instance per CPU core. Intelligent round-robin load balancing distributes requests evenly.

Understanding when to graduate to full worker-queue architecture matters. See our guide on Queue Mode vs Regular Mode for scaling decisions.

Database and Security Configurations

Moving from SQLite to PostgreSQL

The default SQLite database degrades during concurrent access. PostgreSQL handles multiple connections without breaking a sweat.

Migration steps:

  1. Stop PM2: pm2 stop n8n
  2. Update database environment variables in your configuration file
  3. Restart: pm2 restart n8n –update-env

The pm2 update command ensures correct credential usage.

SSL/TLS with Nginx

NGINX website.

Secure deployments require encryption. Nginx acts as a reverse proxy, listening on port 443 and forwarding to n8n on port 5678.

Configure your Nginx server block, then restart Nginx:

sudo systemctl restart nginx

Let’s Encrypt provides free SSL certificates. Set the WEBHOOK_TUNNEL_URL variable to ensure external systems trigger workflows via HTTPS.

Protect your encryption key by never committing it to repositories.

Build Your App Now with Hostinger Horizons
Turn your idea into a powerful app in minutes with Hostinger Horizons. No coding, no hassle, just AI-powered building that brings your vision to life.
Visit Hostinger

Choosing the Right VPS for Your Setup

Your PM2-managed n8n deployment needs reliable infrastructure. A properly configured server makes everything we’ve discussed work smoothly.

When selecting a VPS provider, consider RAM availability, CPU cores for cluster mode, and SSD storage for database performance. Linux platforms significantly outperform Windows, consuming less RAM and lowering costs.

Browse VPS options that match your automation workload. Whether you’re running a Raspberry Pi experiment or production workflows, the right hosting foundation matters.

For n8n-specific recommendations, check our guide to the best n8n hosting providers.

Troubleshooting Common Issues

Fixing Authentication and Path Errors

Basic authentication failures often stem from improper environment variable syntax. Always use –update-env when restarting and run pm2 save afterward.

Windows Specifics: PM2 may fail to locate binaries. Execute commands directly from C:\Users\%AppData%\Roaming\npm\node_modules\n8n\bin.

Global installations with root privileges cause permission errors. Always install PM2 and n8n as the user who will run the services.

Managing Memory Limits Effectively

Never set memory limits equal to your total server RAM. The operating system and PM2 need overhead too.

Best Practice: Configure max_memory_restart to 75-80% of available memory. On a 2GB server, that’s roughly 1.5GB maximum.

Performance Benchmarking and Backups

Single-Instance vs. Multi-Instance Throughput

A single n8n instance achieves up to 220 workflow executions per second on modest hardware. Latency increases under concurrent load, but self hosted deployments handle most use cases comfortably.

Queue mode architecture sustains higher throughput by separating webhook receivers from workers. This matters when you build automation workflows at enterprise scale.

Automated Workflow Backups

Implement scheduled workflows to export credentials and data to S3-compatible storage. Regular PostgreSQL backups protect against corruption.

Use VACUUM commands periodically to reclaim disk space from pruned execution records. Automate tasks like this through n8n itself for maximum efficiency.

Considering alternatives? Our n8n vs Node-RED comparison covers similar deployment patterns.

VPS
Cheap VPS
best option

Conclusion

PM2 transforms fragile n8n sessions into production-grade automation infrastructure. You’ve learned to install, configure, monitor, and scale your instance with confidence. Memory limits prevent crashes. Cluster mode maximizes hardware. PostgreSQL and Nginx handle production demands.

Your workflows now survive reboots, recover from failures, and scale with your needs. That’s the power of proper process management.

Next Steps: What Now?

  1. Create your ecosystem configuration file with production-ready settings.
  2. Set up PM2 startup scripts for automatic recovery after server reboots.
  3. Configure memory limits appropriate for your server’s resources.
  4. Migrate from SQLite to PostgreSQL for better concurrent performance.
  5. Implement SSL/TLS through Nginx for secure webhook traffic.
  6. Schedule automated backups of your workflows and database.
  7. Enable new features like metrics endpoints for external monitoring.

Frequently Asked Questions

How to start n8n with PM2?

Run pm2 start n8n or use an ecosystem file with pm2 start ecosystem.config.js. Save your setup with pm2 save to persist across reboots.

Can I run n8n on my computer?

Yes. Install Node.js, then run npm install -g n8n. Access the interface at localhost:5678 after starting it.

How to run n8n locally after installation?

Execute n8n start in your terminal. The web interface opens at localhost:5678. Use PM2 for persistent local development.

How to run process with PM2?

Use pm2 start [app-name] or reference a config file. PM2 manages the process lifecycle automatically with monitoring and restart capabilities.

Handling Webhook Traffic at Scale in n8n

N8n webhook scaling breaks down faster than you'd expect. When request volumes spike, concurrency pressure builds, and executions start backin...
8 min read
Christi Gorbett
Christi Gorbett
Content Marketing Specialist

Running n8n in Production - Stability Checklist

Getting workflows live is only half the battle. n8n production stability is what keeps your automations running reliably when it actually matt...
8 min read
Christi Gorbett
Christi Gorbett
Content Marketing Specialist

CI/CD Pipelines for Deploying n8n Updates

Manually pushing n8n updates across environments is error-prone and time-consuming. A well-configured n8n CI/CD pipeline changes that. It auto...
8 min read
Christi Gorbett
Christi Gorbett
Content Marketing Specialist

Running n8n with Docker Compose vs Bare-Metal VPS

Choosing between n8n Docker Compose vs bare metal VPS comes down to more than personal preference. It affects how you deploy, scale, and maint...
8 min read
Christi Gorbett
Christi Gorbett
Content Marketing Specialist
Click to go to the top of the page
Go To Top
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.