PM2 Windows Startup Utility
This package enables PM2 (Process Manager 2) to automatically resurrect its saved process list upon Windows operating system startup. It achieves this by adding a specific entry to the Windows Registry that triggers PM2 on boot, leveraging the `start-on-windows-boot` library for low-level registry manipulation. The current stable version is 1.0.3, indicating a mature and stable utility that is likely in maintenance mode rather than active feature development. Its primary differentiator is its focused solution for automating PM2 process continuity specifically within Windows environments, which is crucial for server stability and uptime after system reboots. It serves as a dedicated tool for system administrators and developers deploying Node.js applications with PM2 on Windows servers.
Common errors
-
Error: Access is denied.
cause Attempting to modify the Windows Registry without sufficient permissions.fixClose your current terminal, then restart it by right-clicking and selecting 'Run as administrator'. Execute `pm2-startup install` again. -
Error: EPERM: operation not permitted, open 'C:\Users\<YourUser>\.pm2\dump.pm2'
cause PM2 cannot write its process dump file, often due to permissions or a corrupted installation.fixEnsure the current user has write permissions to the `.pm2` directory (usually in the user's home folder). If this persists, try reinstalling PM2 and `pm2-windows-startup` globally. -
PM2 processes are not starting automatically after Windows reboot.
cause The `pm2 save` command was likely not executed after starting applications or `pm2-startup install` failed to register correctly.fixFirst, ensure `pm2-startup install` completed successfully (run as Administrator). Then, make sure you've started your applications with PM2 and explicitly run `pm2 save` to persist the process list.
Warnings
- gotcha The `pm2-startup install` command requires Administrator privileges on Windows to modify the system registry. Running without elevated permissions will result in an 'Access is denied' or 'EPERM' error.
- gotcha After installing the startup utility, you MUST run `pm2 save` to persist the current list of PM2 processes. If `pm2 save` is not executed, PM2 will start on boot but will not resurrect any applications.
- breaking This package specifies Node.js engine compatibility `>=0.10`. While it might function on modern Node.js versions, compatibility issues could arise with very old or very new Node.js releases, especially concerning underlying dependencies or system APIs it interacts with.
Install
-
npm install pm2-windows-startup -
yarn add pm2-windows-startup -
pnpm add pm2-windows-startup
Imports
- pm2-startup
import pm2Startup from 'pm2-windows-startup'
pm2-startup install
Quickstart
npm install pm2-windows-startup -g pm i -g pm2 # Ensure PM2 is also installed globally if not already pm i -g pm2-logrotate # Optional: for log management # Install the PM2 startup script into Windows Registry pm2-startup install # Start your Node.js application(s) with PM2, e.g. pm2 start app.js --name 'my-node-app' # Crucially, save the current PM2 process list so it can be resurrected on startup pm2 save