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
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/
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With