i can't upload image to my Ubuntu server when i use PM2

Posted February 15, 2017 4.8k views

i deployed my project following this link :
everything is ok , when i start my app with :
node server.js
i can upload image to server
but when i use pm2 :
pm2 start server.js
i cant upload image to server ..
i tried to see logs : pm2 doesn’t restart app when i post upload request
any help please ???

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

im still learning but looks like i fixed it for now, make sure you update pm2

  • npm install pm2@next -g
  • pm2 update

and start pm2 watching files but ignoring the folder and files where you are uploading, so for me it was the “uploads” folder in the same directory that i dont want pm2 to watch

sudo pm2 start server.js –watch –ignore-watch=“./uploads”

restart pm2 inbetween changes
sudo pm2 restart <id number>

this way when i update my app it will restart the app, but i dont want it restarting if i just upload a file for example. Looks like it’s working for me anyway. otherwise ill just use nodemon to serve my app i guess

i have the same problem, when i start with node or nodemon it uploads fine, but pm2 doesnt, its like it restarts before it can finish loading i get 502 bad gateway