### Start Applications Source: https://pm2.keymetrics.io/docs/usage/quick-start Commands to start, daemonize, and monitor various types of applications. ```bash $ pm2 start app.js ``` ```bash $ pm2 start bashscript.sh $ pm2 start python-app.py --watch $ pm2 start binary-file -- --port 1520 ``` -------------------------------- ### Install PM2 Source: https://pm2.keymetrics.io/docs/usage/quick-start Install the latest version of PM2 globally using NPM or Yarn. ```bash $ npm install pm2@latest -g # or $ yarn global add pm2 ``` -------------------------------- ### Start Application with Watch Mode Source: https://pm2.keymetrics.io/docs/usage/quick-start Starts an application with file watching enabled, automatically restarting on changes while ignoring specified directories. ```bash $ cd /path/to/my/app $ pm2 start env.js --watch --ignore-watch="node_modules" ``` -------------------------------- ### Start application in Cluster mode Source: https://pm2.keymetrics.io/docs/usage/quick-start Starts an application using the built-in load balancer with the maximum number of available CPU cores. ```bash $ pm2 start app.js -i max ``` -------------------------------- ### Manage Ecosystem configuration Source: https://pm2.keymetrics.io/docs/usage/quick-start Commands to generate and start applications using an ecosystem configuration file. ```bash $ pm2 ecosystem ``` ```javascript module.exports = { apps : [{ name: "app", script: "./app.js", env: { NODE_ENV: "development", }, env_production: { NODE_ENV: "production", } }, { name: 'worker', script: 'worker.js' }] } ``` ```bash $ pm2 start ecosystem.config.js ``` -------------------------------- ### Update PM2 globally Source: https://pm2.keymetrics.io/docs/usage/quick-start Installs the latest version of PM2 globally using npm. ```bash npm install pm2@latest -g ``` -------------------------------- ### Update in-memory PM2 Source: https://pm2.keymetrics.io/docs/usage/quick-start Synchronizes the running PM2 process manager with the newly installed version. ```bash pm2 update ``` -------------------------------- ### PM2 CLI Options Source: https://pm2.keymetrics.io/docs/usage/quick-start Common configuration flags for managing application behavior, logging, and restart policies. ```bash # Specify an app name --name # Watch and Restart app when files change --watch # Set memory threshold for app reload --max-memory-restart <200MB> # Specify log file --log # Pass extra arguments to the script -- arg1 arg2 arg3 # Delay between automatic restarts --restart-delay # Prefix logs with time --time # Do not auto restart app --no-autorestart # Specify cron for forced restart --cron # Attach to application log after start --attach # Run the PM2 daemon in the foreground --no-daemon ``` -------------------------------- ### Generate PM2 Startup Script Source: https://pm2.keymetrics.io/docs/usage/quick-start Generates a startup script to ensure PM2 and managed processes restart automatically on system boot. ```bash $ pm2 startup ``` -------------------------------- ### List managed applications Source: https://pm2.keymetrics.io/docs/usage/quick-start Displays the status of all applications currently managed by PM2. ```bash $ pm2 [list|ls|status] ``` -------------------------------- ### Display application logs Source: https://pm2.keymetrics.io/docs/usage/quick-start Commands for viewing real-time logs or retrieving a specific number of historical log lines. ```bash $ pm2 logs ``` ```bash $ pm2 logs --lines 200 ``` -------------------------------- ### PM2 Command Cheatsheet Source: https://pm2.keymetrics.io/docs/usage/quick-start A collection of common commands for process management, scaling, monitoring, and logging. ```bash # Fork mode pm2 start app.js --name my-api # Name process # Cluster mode pm2 start app.js -i 0 # Will start maximum processes with LB depending on available CPUs pm2 start app.js -i max # Same as above pm2 scale app +3 # Scales `app` up by 3 workers pm2 scale app 2 # Scales `app` up or down to 2 workers total # Listing pm2 list # Display all processes status pm2 jlist # Print process list in raw JSON pm2 prettylist # Print process list in beautified JSON pm2 describe 0 # Display all information about a specific process pm2 monit # Monitor all processes # Logs pm2 logs [--raw] # Display all processes logs in streaming pm2 flush # Empty all log files pm2 reloadLogs # Reload all logs # Actions pm2 stop all # Stop all processes pm2 restart all # Restart all processes pm2 reload all # Will 0s downtime reload (for NETWORKED apps) pm2 stop 0 # Stop specific process id pm2 restart 0 # Restart specific process id pm2 delete 0 # Will remove process from pm2 list pm2 delete all # Will remove all processes from pm2 list # Misc pm2 reset # Reset meta data (restarted time...) pm2 updatePM2 # Update in memory pm2 pm2 ping # Ensure pm2 daemon has been launched pm2 sendSignal SIGUSR2 my-app # Send system signal to script pm2 start app.js --no-daemon pm2 start app.js --no-vizion pm2 start app.js --no-autorestart ``` -------------------------------- ### Terminal-based monitoring Source: https://pm2.keymetrics.io/docs/usage/quick-start Launches a real-time monitoring dashboard directly within the terminal. ```bash $ pm2 monit ``` -------------------------------- ### PM2 Plus monitoring Source: https://pm2.keymetrics.io/docs/usage/quick-start Accesses the web-based monitoring and diagnostic interface. ```bash $ pm2 plus ``` -------------------------------- ### Manage Process State Source: https://pm2.keymetrics.io/docs/usage/quick-start Commands to control the lifecycle of running processes by name, ID, or all at once. ```bash $ pm2 restart app_name $ pm2 reload app_name $ pm2 stop app_name $ pm2 delete app_name ``` -------------------------------- ### Save Process List Source: https://pm2.keymetrics.io/docs/usage/quick-start Freezes the current list of managed processes so they can be respawned after a reboot. ```bash $ pm2 save ``` -------------------------------- ### Update PM2 Runtime Source: https://pm2.keymetrics.io/docs/usage/quick-start Updates the PM2 package globally and refreshes the in-memory daemon. ```bash npm install pm2@latest -g ``` ```bash pm2 update ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.