资源链接

文档
https://pm2.keymetrics.io/docs/usage/pm2-doc-single-page/

Using PM2 with transpilers

https://pm2.io/doc/en/runtime/integration/transpilers/?utm_source=pm2&utm_medium=website&utm_campaign=rebranding

babel

Install the Babel CLI globally:
npm install -g babel-cli

## Start pm2 with the Babel CLI binary in watch mode:
pm2 start —watch —interpreter babel-cli app.js

或者本地安装babel-cli
pm2 start ./server.js —interpreter ./node_modules/babel-cli/bin/babel-node.js
https://stackoverflow.com/questions/48637156/how-to-use-babel-node-with-pm2


typescript

Add the new typescript dependency in PM2:
pm2 install typescript

## Start app.ts in watch & restart:
pm2 start app.ts —watch


配置文件

栗子

  1. 将以下PM2配置文件与package.json放到一个根目录下
  2. 在package.json 的scripts里添加 “pm2”: “pm2 start pm2.json”这一段代码这样我们就可以使用 npm run pm2来启动我们的Node项目 ```json { “apps”: { “name”: “wuwu”, // 项目名
    “script”: “./bin/www”, // 执行文件 “cwd”: “./“, // 根目录 “args”: “”, // 传递给脚本的参数 “interpreter”: “”, // 指定的脚本解释器 “interpreter_args”: “”, // 传递给解释器的参数 “watch”: true, // 是否监听文件变动然后重启 “ignore_watch”: [ // 不用监听的文件
    1. "node_modules",
    2. "logs"
    ], “exec_mode”: “cluster_mode”, // 应用启动模式,支持fork和cluster模式 “instances”: 4, // 应用启动实例个数,仅在cluster模式有效 默认为fork;或者 max “max_memory_restart”: 8, // 最大内存限制数,超出自动重启 “error_file”: “./logs/app-err.log”, // 错误日志文件 “out_file”: “./logs/app-out.log”, // 正常日志文件 “merge_logs”: true, // 设置追加日志而不是新建日志 “log_date_format”: “YYYY-MM-DD HH:mm:ss”, // 指定日志文件的时间格式 “min_uptime”: “60s”, // 应用运行少于时间被认为是异常启动 “max_restarts”: 30, // 最大异常重启次数,即小于min_uptime运行时间重启次数; “autorestart”: true, // 默认为true, 发生异常的情况下自动重启 “cron_restart”: “”, // crontab时间格式重启应用,目前只支持cluster模式; “restart_delay”: “60s”, // 异常重启情况下,延时重启时间 “env”: {
    1. "NODE_ENV": "production", // 环境参数,当前指定为生产环境 process.env.NODE_ENV
    2. "REMOTE_ADDR": "爱上大声地" // process.env.REMOTE_ADDR
    }, “env_dev”: {
    1. "NODE_ENV": "development", // 环境参数,当前指定为开发环境 pm2 start app.js --env_dev
    2. "REMOTE_ADDR": ""
    }, “env_test”: { // 环境参数,当前指定为测试环境 pm2 start app.js —env_test
    1. "NODE_ENV": "test",
    2. "REMOTE_ADDR": ""
    } } }

``` https://juejin.im/post/5b173fa8f265da6e484cf163

windows上的设置

https://blog.cloudboost.io/nodejs-pm2-startup-on-windows-db0906328d75

When you install PM2 (npm install -g pm2),
it creates a default PM2 home folder (under C:\Users\.pm2) that will store PM2 relevant files,
like logs (yes, the same you see running pm2 logs), process pid or the dump that is created when you run pm2 save.
I recommend to run your PM2 commands and check how files change in that folder.
Now, we will move that folder to a brand new folder: c:\etc.pm2

  1. Create a new folder c:\etc\.pm2
    2. Create a new PM2_HOME variable (at System level, not User level) and set the value c:\etc\.pm2
    3. Close all your open terminal windows (or restart Windows)
    4. Ensure that your PM2_HOME has been set properly, running echo %PM2_HOME%

(1) Create a file (ecosystem.config.js)that describes how the application should starts.(2) Load configuration running:pm2 reload ecosystem.config.js --env=production(3) Check that your application is working as expected
(4) If everything is ok, save your configuration: pm2 save

Now, the final step is to test that everything has been done properly.(1) Kill PM2 running: pm2 kill(2) Restart PM2: pm2 resurrect

https://stackoverflow.com/questions/42758985/windows-auto-start-pm2-and-node-apps
npm install pm2 -g
npm install pm2-windows-startup -g
pm2-startup install
pm2 start myApp.js —name mySuperApp
pm2 save
reboot
pm2 ls

Annex

入门教程
https://www.cnblogs.com/chyingp/p/pm2-documentation.html

官方文档
https://pm2.io/doc/en/runtime/overview/


??
http://imweb.io/topic/57c8cbb27f226f687b365636


npm install -g pm2


在当前user执行:
奇怪在root反倒不行(执行pm2 startup失败)

pm2 start node-red
pm2 info node-red
pm2 logs node-red
pm2 save
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u zcs —hp /home/zcs
pm2 show node-red