0
votes

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!

1

1 Answers

0
votes

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
        }
    }]
}