brief introduction
PM2 is a process management of Node application with load balancing function!
Built in load balancing (using Node cluster cluster module)
Can run in the background
It can shut down and reload in 0 seconds. (it can be understood that there is no need to shut down and restart, and we have updated the program when the user is browsing the page happily.)
Console detection
Log management
Hot heavy load
...
Related configuration
{ "apps": { "name": "wuwu", // Project name "script": "./bin/www", // Execution document "cwd": "./", // root directory "args": "", // Parameters passed to script "interpreter": "", // Specified script interpreter "interpreter_args": "", // Parameters passed to interpreter "watch": true, // Whether to listen for file changes and restart "ignore_watch": [ // Files not to be monitored "node_modules", "logs" ], "exec_mode": "cluster_mode", // Application startup mode, support fork and cluster mode "instances": 4, // The number of application startup instances, valid only in cluster mode, default to fork; or max "max_memory_restart": 8, // Maximum memory limit, auto restart exceeded "error_file": "./logs/app-err.log", // Error log file "out_file": "./logs/app-out.log", // Normal log file "merge_logs": true, // Set append log instead of new log "log_date_format": "YYYY-MM-DD HH:mm:ss", // Specify the time format of the log file "min_uptime": "60s", // Application running less than time is regarded as abnormal startup "max_restarts": 30, // The maximum number of abnormal restarts, that is, the number of restarts less than the Min uptime running time; "autorestart": true, // The default value is true. It will restart automatically in case of exception "cron_restart": "", // Restart the application in crontab time format. Currently, only cluster mode is supported; "restart_delay": "60s" // Delay restart time in case of abnormal restart "env": { "NODE_ENV": "production", // Environment parameter, currently specified as the production environment process.env.node'env "REMOTE_ADDR": "Fall in love with loud" // process.env.REMOTE_ADDR }, "env_dev": { "NODE_ENV": "development", // Environment parameter, currently specified as development environment pm2 start app.js --env_dev "REMOTE_ADDR": "" }, "env_test": { // Environment parameter, currently specified as test environment pm2 start app.js --env_test "NODE_ENV": "test", "REMOTE_ADDR": "" } } }
Reference article: https://juejin.im/post/5b173fa8f265da6e484cf163
pm2 start command: https://blog.csdn.net/sunqy1995/article/details/82892364