0

I want to upload an image using node(11.10.1),pm2(3.4.0),through Ubuntu 16.04. Like many others who have tried, I can receive an image from starting my server through node process but once I use PM2 to upload an image, PM2 restarts the server and there is no image uploaded.

I made a ecosystem and set different types of settings around like , watch, ignore, autoreset, cwd. I also tried the cli line of code where it is "sudo pm2 start server.js --ignore-watch "/public/images". I am not sure how I can ignore Pm2 the right way. I also made sure that i do have a file path at Myapp/public/images/

I have tried the following: Multer upload files with PM2 Expressjs pm2 ignore watch public/images folder https://pm2.io/doc/en/runtime/guide/ecosystem-file/ http://pm2.keymetrics.io/docs/usage/watch-and-restart/

my file structure:

    >MyApp 
       >ecosystem.config.js 
       >server.js  
       >public 
          >images
       >routes

this is my ecosystem

  'apps' : [{
    'name': 'pm2_checking_server',
    'script': 'server.js',
    'cwd': '/var/www/MyApp/'//........also tried it without cwd
    'watch': ['server.js'], //...........I also did true/false
    'ignore_watch': ['public/images/'],//...did variations like ./public/images, public/images... etc
    'watch_options': {
     'followSymlinks': false
    }
}],

this is my multer destination in MyApp/routes/

destination: function (req, files, cb) {

      cb(null, path.join(__dirname , '../public/images'))
}

I expect Pm2 to ignore the watching file upload but the response back I get from uploading an Image is "errno": -13, "code": "EACCES", "syscall": "open", "path": "/var/www/MyApp/public/images/7ylxlncRKJ

thank you for your help!

ebbandflows
  • 63
  • 3
  • 8

1 Answers1

0

As far as I see the difference with official examples is you are using single quote ' and they have used double quote " after all this is a json file. Also you have missing a , at line:

"cwd": "/var/www/MyApp/",

Delete trailing / at: public/images/

So this is your process.json file which should be at root of your project:

{
    "apps": [{
        "name": "pm2_checking_server",
        "script": "server.js",
        "cwd": "/var/www/MyApp/",
        "watch": ["server.js"],
        "ignore_watch": ["public/images"],
        "watch_options": {
            "followSymlinks": false
        }
    }]
}
  • Thank you for your quick response I added the double quotes and sorry for removing the comma there, I wanted to add comments there and accidentally removed it. I still have the same problem. module.exports = { "apps" : [{ "name": "pm2_checking_server", "script": "server.js", "cwd": "/var/www/MyApp/", "watch": ["server.js"], "ignore_watch": ["public/images/"], "watch_options": { "followSymlinks": false } }], }; – ebbandflows Apr 05 '19 at 22:09
  • 1
    Paste your config in an online [json validator](https://jsonlint.com/) and check its validity. I'm pretty sure something is wrong with your config. Actually this is the only thing that cause problem you have at hand. –  Apr 05 '19 at 22:15
  • I just validated and changed it around( I had to remove the comma after the app[array] and change some white spaces around). I still cannot upload an image. I am also using "sudo pm2 start ecosystem.config.js" at /var/www/MyApp for your reference as well. – ebbandflows Apr 05 '19 at 22:30
  • @ebbandflows: `ecosystem.config.js` ?! You are using the json version of config file and it should be `ecosystem.json`. –  Apr 06 '19 at 11:05
  • I had the js version because of https://pm2.io/doc/en/runtime/guide/ecosystem-file/ said to do a pm2 init. I also tried to make it into a json file, but I still have the same result when i upload. – ebbandflows Apr 07 '19 at 16:44
  • I have the changed JSON code you posted as well as different variations on it which gave me the same result. I ran it from /var/www/MyApp where I used sudo pm2 and started ecosystem.json. I saw that there is a post on https://github.com/Unitech/pm2/issues/2629 where this issue is remaining? Also, thank you for your help i really appreciate it! – ebbandflows Apr 07 '19 at 16:44