If you are searching for how to clear the PM2 cache, the first thing to know is that PM2 does not provide one universal “clear cache” command. The right solution depends on what is causing the problem: old application output may be in PM2’s logs, outdated environment variables may be held by a running process, or PM2 may be restoring saved process information. In other cases, the stale data may belong to Node.js, npm, or your application rather than PM2.
This guide explains how to clear PM2 logs, restart processes with updated settings, remove saved process state, and reset PM2’s local data when necessary. Start with the least disruptive option. Some reset steps stop applications or permanently remove logs and saved configuration, so check what you are deleting before you run a command.
What Does “PM2 Cache” Mean?
PM2 is a process manager for Node.js applications. It keeps track of managed processes and may store logs, process metadata, configuration, and a saved process list. These files are useful for monitoring applications and restoring them after a restart, but they are not all a single cache.
When someone says they want to clear the PM2 cache, they may mean one of several things:
- Old or excessive logs: PM2’s output and error log files are taking up space or showing outdated messages.
- Stale environment variables: An application continues using old settings after its environment was changed.
- A process that needs a clean restart: The app is behaving as if old code or state is still loaded.
- Saved process information: PM2 restores an old process list when its daemon or server starts.
- Node.js or build-tool cache: The application uses cached dependencies or build output that PM2 does not control.
Identifying which issue you have matters. Clearing logs will not update an application’s environment variables, and deleting PM2’s data directory will not remove a cache maintained by a build tool.
Check Your PM2 Processes Before Clearing Anything
Before making changes, check which applications PM2 is managing and where PM2 stores its files:
pm2 list
pm2 info <app-name-or-id>
pm2 report
The first command lists managed processes. The second shows details about one process, including its status and, depending on your setup, its log paths. The report command provides diagnostic information that can help when troubleshooting. Review the output so you do not accidentally stop or remove the wrong application.
PM2 usually stores its data in a .pm2 directory under the home directory of the user running PM2. The location can differ if the PM2_HOME environment variable is set or if PM2 runs under a service account. On Linux and macOS, the default is commonly ~/.pm2. On Windows, it is commonly %USERPROFILE%\.pm2.
Clear PM2 Logs Without Removing Your Applications
If you only want to empty PM2’s current log files, use:
pm2 flush
This flushes PM2-managed application logs. It does not delete your applications, clear Node.js module caches, or reset the saved process list. It is often the safest first step when old output is cluttering your logs or consuming disk space.
To review the logs before flushing them, run:
pm2 logs
PM2 commonly keeps log files in ~/.pm2/logs, though your PM2 home directory or application configuration may change that location. If you need to remove specific log files manually, confirm the paths first. Deleting files from the wrong PM2 directory can affect a different user or service.
For ongoing log growth, consider using PM2’s log rotation module rather than repeatedly deleting files by hand. Log rotation can limit file size and retain a chosen number of older logs. This helps prevent a recurring disk-space problem while preserving recent information for troubleshooting.
Restart an Application to Clear Its In-Memory State
PM2 does not generally hold your application’s JavaScript module cache as a separate cache that you can clear with a PM2 command. A Node.js process loads code and modules into memory when it runs. Restarting that process creates a fresh process and reloads the application.
Restart one application by name or ID:
pm2 restart <app-name-or-id>
To restart every PM2-managed application, use:
pm2 restart all
Restarting all processes affects every application managed by that PM2 instance, so use the targeted command when possible. A restart may also briefly interrupt service. For supported applications, pm2 reload can perform a reload with less downtime, but its behavior depends on the application’s execution mode and configuration.
If you have changed environment variables, a regular restart may not apply the updated values in every situation. Ask PM2 to refresh the environment when restarting:
pm2 restart <app-name-or-id> --update-env
You can also use --update-env with a reload where appropriate. Check the process details and your deployment configuration afterward to confirm that the application is using the expected settings.
Remove a Process or Reset PM2’s Saved Process List
Use pm2 delete when you want PM2 to stop managing a particular application, rather than merely restart it:
pm2 delete <app-name-or-id>
To delete all processes from the current PM2 instance, run:
pm2 delete all
This stops and removes the selected processes from PM2’s active list. It is a significant change, especially on a production server. If PM2’s saved process list is used to restore applications after a reboot, update that saved list deliberately. For example, after arranging the processes you want to keep, save the current list with:
pm2 save
Be careful: pm2 save writes the current process list as the list PM2 can restore later. Saving after deleting everything can replace a previously useful saved list with an empty one. If the issue is that PM2 resurrects unwanted applications, inspect the list and your startup setup before changing or removing the saved state.
Stop the PM2 Daemon
If PM2 itself appears stuck, you can stop its daemon with:
pm2 kill
This stops the PM2 daemon and the processes it manages. Your applications will therefore stop as well; the command is not a harmless cache flush. Use it only when you are prepared for the interruption, and make sure you know how the applications will be started again.
Afterward, you can start an application again using its ecosystem file or the appropriate PM2 start command. For example:
pm2 start ecosystem.config.js
If you use a different ecosystem filename or deployment workflow, use that instead. On a server, also consider whether a system service or startup integration will automatically bring the daemon back up.
Completely Reset PM2’s Local Data
For a full reset, stop the PM2 daemon and then remove the PM2 data directory used by the relevant account. On Linux or macOS, a typical sequence is:
pm2 kill
rm -rf ~/.pm2
On Windows, the default directory is often %USERPROFILE%\.pm2. Confirm the actual PM2 home before deleting anything, particularly if PM2 runs as a Windows service or under another user account.
Removing this directory can permanently delete PM2 logs, saved process information, and other PM2 state. It does not uninstall Node.js or remove your application’s source code. However, PM2 may no longer know which processes to restore. Back up any files you need, such as the saved process list or logs, before carrying out a full reset. If you use a custom PM2_HOME, deleting ~/.pm2 may not reset the directory PM2 actually uses.
A full reset is usually unnecessary for routine troubleshooting. Try flushing logs, restarting the affected process, or updating its environment first. Reserve deletion of the PM2 directory for cases where you specifically need to discard PM2’s local state and understand the consequences.
What If the Stale Cache Belongs to Node.js or Your Build Tool?
PM2 manages processes; it does not automatically clear every cache involved in building or running an application. If your app still serves old assets after a PM2 restart, investigate the build output, deployment path, reverse proxy, browser, content delivery network, or application-level cache.
Likewise, npm’s cache is separate from PM2. If you have evidence that npm’s package cache is causing a dependency-installation problem, inspect it with:
npm cache verify
A Node.js application’s in-memory module state is generally refreshed by restarting the process. A build tool may have its own cache-cleaning command, and a framework may provide a specific way to clear generated files. Use the documentation for the exact tool and version rather than deleting unrelated directories.
Also verify that PM2 is running the code you just deployed. Check the application’s working directory, script path, ecosystem configuration, and deployment process. Restarting a process cannot make PM2 use new files if the new build was placed in a different directory or was never deployed.
Common PM2 Cache-Clearing Mistakes
-
Using
pm2 flushto refresh application code: This clears logs, not the running process or its loaded code. -
Running
pm2 killwithout planning for downtime: It stops PM2-managed applications along with the daemon. -
Deleting
~/.pm2without a backup: This can remove logs and process data needed for recovery. -
Saving an empty process list: Running
pm2 saveafter deleting applications may overwrite the list used for restoration. - Clearing npm or build caches without evidence: These caches are separate from PM2 and may not be related to the problem.
-
Using the wrong account or PM2 home: A service user or custom
PM2_HOMEmay store PM2 data somewhere other than your own home directory.
Conclusion
To clear the PM2 cache, first identify what you mean by “cache.” Use pm2 flush to clear PM2 logs, restart the affected process to refresh its in-memory state, and add --update-env when you need changed environment variables applied. Use pm2 delete to remove managed processes, and treat pm2 kill or deleting the PM2 data directory as disruptive reset options.
There is no single PM2 command that safely clears every kind of stale data. Check the process list, confirm PM2’s data directory, and back up important state before making destructive changes. If a restart does not resolve the issue, the cache may belong to your application, Node.js tooling, build process, browser, or proxy rather than PM2.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.