简体   繁体   English

VPS 上的 Nodemon 和 PM2

[英]Nodemon and PM2 on VPS

I have a nodeJS app and I developp it with nodemon to restart everytime something change.我有一个 nodeJS 应用程序,我用 nodemon 开发它以在每次发生变化时重新启动。 So my package.json is like:所以我的 package.json 就像:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon server.js"
  },

But on production I have PM2.但是在生产中我有 PM2。 So do I need to keep nodemon with PM2?那么我是否需要将 nodemon 与 PM2 一起保留? Because in my mind they do the same thing, I can --watch file with PM2 to restart automatically if anything change.因为在我看来他们做同样的事情,我可以 --watch file with PM2 在有任何变化时自动重启。

If yes, do I need to make a script for production (no nodemon) and another for dev?如果是,我是否需要制作一个用于生产的脚本(没有 nodemon)和另一个用于开发的脚本?

You shouldn't need nodemon if you are using PM2, as you had stated, they are doing the same thing.正如您所说,如果您使用的是 PM2,则不需要 nodemon,它们正在做同样的事情。

Nodemon is really more a development tool in my opinion, not to say you can't use it like this but most prod stacks will probably want to have clustering so pm2 would work better.在我看来,Nodemon 实际上更像是一个开发工具,并不是说你不能像这样使用它,但大多数产品堆栈可能都希望有集群,所以 pm2 会更好地工作。

So..所以..

local environment - Nodemon Prod - PM2 (clustering etc)本地环境 - Nodemon Prod - PM2(集群等)

So in your ecosystems file, just set the watch flag then pm2 ecosystem file and you should be good to go..因此,在您的生态系统文件中,只需设置 watch 标志然后 pm2 生态系统文件,您应该对 go..

I have a similar use case.我有一个类似的用例。 I have a node.js application, app.js.我有一个 node.js 应用程序,app.js。 I want node.js to automatically restart the application anytime the file app.js changes.我希望 node.js 在文件 app.js 更改时自动重启应用程序。

I had previously started my application with pm2 start app.js .我之前使用pm2 start app.js启动了我的应用程序。

To accomplish the above, I simply entered the command pm2 retart app.js --watch .为了完成上述任务,我简单地输入了命令pm2 retart app.js --watch

The --watch parameter is documented here . --watch参数记录在此处

My environment: Ubuntu 20.04, node.js 14.19.1, pm2 5.2.0.我的环境:Ubuntu 20.04,node.js 14.19.1,pm2 5.2.0。

I did not install nodemon.我没有安装 nodemon。 Pm2 alone did the trick.仅 Pm2 就可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM