使用pm2托管我的后台服务已经有一段时间了
之前直接就是
1 | pm2 start app.js --name myapp --watch |
后来发现不可避免的需要使用npm命令启动,比如想通过nodemon启动,命令是npm run dev
于是查找了一下pm2通过npm运行的方法:
1 | pm2 start npm -- start --watch |
然后想当然的就
1 | pm2 start npm -- run dev --name myapp --watch |
启动之后发现,项目被命名为了npm?
后来一想应该是参数位置的原因
正确的方法是
1 | pm2 start npm --name myapp -- run dev --watch |
但是发现–watch没有生效
查看了pm2官网,发现官方说明:
PM2 can automatically restart your application when a file is modified in the current directory or its subdirectories
所以最终使用了
1 | pm2 start ./bin/www --name myapp --watch |
因为其实express也是通过./bin/www来启动的
都是可以监听变化的