当前位置: 首页 > 后端技术 > Node.js

pm2

时间:2023-04-03 20:58:49 Node.js

的使用方法1.安装建议全局安装npmipm2-g2。生成配置文件ecosystem.config.js安装好pm2后,执行pm2init3。apps:[{name:'xxx',//服务名称script:'./bin/www',//选项参考:https://pm2.io/doc/en/runtime/reference/ecosystem-file///args:'',instances:1,autorestart:true,watch:false,output:'./output.log',error:'./error.log',env:{NODE_ENV:"local",},env_dev:{NODE_ENV:"dev",},env_test:{NODE_ENV:"test",},env_production:{NODE_ENV:"production",},max_memory_restart:'1G',wait_ready:true,merge_logs:true}]};4.startpm2,根据配置文件,--env参数对应配置文件中配置的NODE_ENV的值pm2startecosystem.config.js//默认节点环境变量为localpm2startecosystem.config.js--envdev//默认节点环境变量是dev5.pm2的常用命令:pm2start|reload|logs|ps|stop|deletepm2ls//查看进程pm2deletexxx//xxx是配置中的name字段值filepm2restartxxx//重启应用pm2logs//查看日志