windows配置pm2开机自启动
[借鉴]https://www.jianshu.com/p/6cb523c0ced8 cmd使用管理员角色
1.安装pm2: npm i -g pm2
2.配置服务:npm i -g pm2-windows-service
3.修改环境变量(可选):PM2_HOME:D:\.pm2
4.安装服务:pm2-service-install Perform environment setup ?选择n
5.启动node程序:pm2 start app.js --name myapp
6.查询服务列表:pm2 list
7.保存服务:pm2 save
8.删除服务:pm2 delete 1 卸载服务:pm2-service-uninstall
pm2 resurrect复活命令
windows开机自启动目录: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
把下面bat命令放入开机自启动目录:
@ echo off
%1 %2
ver|find "5.">nul&&goto :Admin
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :Admin","","runas",1)(window.close)&goto :eof
:Admin
cmd /k "pm2 resurrect"
echo 执行完毕,任意键退出
pause >nul
exit