简体   繁体   中英

Nodemon and PM2 on VPS

I have a nodeJS app and I developp it with nodemon to restart everytime something change. So my package.json is like:

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

But on production I have PM2. So do I need to keep nodemon with PM2? Because in my mind they do the same thing, I can --watch file with PM2 to restart automatically if anything change.

If yes, do I need to make a script for production (no nodemon) and another for dev?

You shouldn't need nodemon if you are using PM2, as you had stated, they are doing the same thing.

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.

So..

local environment - Nodemon Prod - PM2 (clustering etc)

So in your ecosystems file, just set the watch flag then pm2 ecosystem file and you should be good to go..

I have a similar use case. I have a node.js application, app.js. I want node.js to automatically restart the application anytime the file app.js changes.

I had previously started my application with pm2 start app.js .

To accomplish the above, I simply entered the command pm2 retart app.js --watch .

The --watch parameter is documented here .

My environment: Ubuntu 20.04, node.js 14.19.1, pm2 5.2.0.

I did not install nodemon. Pm2 alone did the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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