Skip to main content
Deploying an application is not the end of the work. Production maintenance means keeping the application running smoothly, catching errors before users report them, applying security patches, backing up data, and scaling when traffic grows. This page covers the full maintenance lifecycle.

Why Maintenance Matters

PM2 Monitoring

Real-Time Dashboard

Shows CPU%, memory, restarts, and log tail for all running processes. Press h for help, q to quit.

Useful PM2 Commands

Winston Production Logging

Sentry: Error Tracking

Sentry captures uncaught exceptions and reports them with full context (stack trace, user ID, request data).
Sentry provides a dashboard where you can see:
  • How many users were affected
  • Stack trace of every error
  • Request details when the error occurred
  • Error frequency over time

Health Check Endpoint

A health check endpoint is the first thing monitoring tools and load balancers call:

Memory Management and Leak Prevention

Node.js uses a garbage collector but memory leaks are still possible.

PM2 Memory Limit

Common Memory Leak Sources

Monitor Memory

Updating Node.js and Dependencies

Update Node.js with NVM

Keep Dependencies Updated

Schedule a monthly maintenance window to review outdated packages and apply updates.

Database Backups

MySQL Backup with mysqldump

Automate with cron via node-cron (see below) or the system crontab:

Scheduled Tasks with node-cron

Cron Syntax Reference

Scaling

Vertical Scaling

Upgrade the server (more CPU, RAM). Simple but limited and has downtime.

Horizontal Scaling

Run multiple instances behind a load balancer.

PM2 Cluster Mode

PM2’s cluster mode runs multiple Node.js processes, one per CPU core, sharing the same port:
Cluster mode requires your app to be stateless. If you store session data in memory, different requests go to different processes and lose the session. Use Redis for shared session/cache storage.

Key Terms