Expressjs pm2 ignore watch public/images folder

可紊 提交于 2019-12-01 15:22:10

问题


I have a website using nodejs. Problem is when user upload images the site stop working. That because of PM2 restart server when file change I think. How to solve this problem. thank you


回答1:


PM2 has special flag --ignore-watch flag.

Try creating file process.json in the same directory where your app.js/index.js is and paste this:

{
  "watch": ["server", "client"],
  "ignore_watch" : ["node_modules", "public/images"],
  "watch_options": {
    "followSymlinks": false
  }
}

More on that topic: http://pm2.keymetrics.io/docs/usage/watch-and-restart/




回答2:


A simple explanation, from actual experience

create a json file in the root folder of the the expressjs application. It can have any name, but I used pm2-process.json for clarity

{
    "script": "bin/www",
    "watch": true,
    "ignore_watch": ["log"],
    "watch_options": {
        "followSymlinks": false
    },
    "name": "YOUR_PM2_PROCESS_NAME"
}

To start your pm2 service from terminal, in the root folder of the express application:

pm2 start pm2-process.json

That's it. Really simple. There are many other options but this is the bare functional minimum .

Fields explanation:

  • script - the script to run the express application
  • watch - a boolean flag to control if pm2 watches (or not) the folder
  • ignore_watch - if watch is on, then tell pm2 which folders to ignore watching (in other words, this is an watch monitor exclusion list)
  • name - the name of the pm2 process ('service'). Set it to your application name of choice.

The full documentation is here: http://pm2.keymetrics.io/docs/usage/application-declaration/#attributes-available

Note: I left the node_modules folder out of the ignore_watch array in the example above, because I want pm2 to restart the service after a git pull and npm i that causes a change in the node modules. However it easy to ignore node_modules or any other folder (e.g., temp, public, etc.) by editing the array values



来源:https://stackoverflow.com/questions/38070869/expressjs-pm2-ignore-watch-public-images-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!