1

i have a express app and am using multer to uploads files, the problem is when i running the app in the production server with PM2 the multer upload file gave me an error:

"Error: ENOENT: no such file or directory, open 'uploads/img.png' at Error (native)"

but when i run it with "Debug=projectname:* npm start" its just work fine.

note that i already create uploads directory with all the permissions "read and write for anyone".

(sorry for my bad english)

1
  • sorry, do you have a solution? because i don't have. i have same problem. Commented Jul 8, 2022 at 9:12

2 Answers 2

1

I will try to guess the problem.

At your pm2 will you don't use cwd param, so your application starts with wrong root directory.

Sign up to request clarification or add additional context in comments.

1 Comment

May you please give an example here, I have tried everything on internet and still having the issue.
0

I have solved the same problem by change relative path to absolute path

var storage = multer.diskStorage({
destination: function(req, file, cb) {
  cb(null, __dirname + '/public/uploads')
},
filename: function(req, file, cb) {
  var fileFormat = (file.originalname).split(".");
  cb(null, file.fieldname + '-' + Date.now() + "." + 
  fileFormat[fileFormat.length - 1]);
}
})

The third line before I change just like below

cb(null, './public/uploads')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.