sarya
By:
sarya

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

February 15, 2017 508 views
Deployment Ubuntu

i deployed my project following this link :
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04
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 ???

2 Answers

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

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

Have another answer? Share your knowledge.