question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENOENT error when deploy to heroku

See original GitHub issue

the error:

2018-05-12T05:47:21.500393+00:00 app[web.1]: HTTP request POST /api/postImage/ {}
2018-05-12T05:47:21.501779+00:00 app[web.1]: HTTP request undefined POST /api/postImage/ {}
2018-05-12T05:47:21.591203+00:00 app[web.1]: { Error: ENOENT: no such file or directory, open '/app/static/uploads/76cc729da26dc8da18cda7924fc5eaf31526104041562.png'
2018-05-12T05:47:21.591209+00:00 app[web.1]: code: 'ENOENT',
2018-05-12T05:47:21.591213+00:00 app[web.1]: syscall: 'open',
2018-05-12T05:47:21.591216+00:00 app[web.1]: path: '/app/static/uploads/76cc729da26dc8da18cda7924fc5eaf31526104041562.png',
2018-05-12T05:47:21.591217+00:00 app[web.1]: storageErrors: [] }
2018-05-12T05:47:21.591207+00:00 app[web.1]: errno: -2,

multer setup:

var multer = require('multer');
var storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, path.join(__dirname, '/static/uploads/'))
        // cb(null, "localhost:" + process.env.PORT + '/static/uploads/')
    },
    filename: function (req, file, cb) {
        crypto.pseudoRandomBytes(16, function (err, raw) {
            cb(null, raw.toString('hex') + Date.now() + '.' + mime.extension(file.mimetype));
        });
    }
});
var upload = multer({storage: storage});

and port is set to: var PORT = process.env.PORT || 3000; project structure: screen shot 2018-05-12 at 01 48 29

what did i mess up?

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

27reactions
jawad-aziz-farhadcommented, Jul 5, 2019

I was having the same issue after deploying my Mean Stack app to heroku. I was pushing the code with empty uploads folder. After adding a temporary file in uploads folder , Issue is gone.

20reactions
LinusUcommented, May 13, 2018

It seems like the /app/static/uploads/ directory doesn’t exist. Might it be that the Heroku client doesn’t upload empty folders? Or that it’s ignored in some .*ignore file?

I would suggest creating the directory when the process starts for the first time:

try {
  fs.mkdirSync(path.join(__dirname, '/static/uploads/'))
} catch (err) {
  if (err.code !== 'EEXIST') throw err
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting Node.js Deploys
Your Node.js deploy failed - now what? Start with these simple steps to troubleshoot a build issue. Check the buildpack.
Read more >
ENOENT error in Heroku deployment when typing in or ...
ENOENT error in Heroku deployment when typing in or redirecting to any route other than index. I have a monorepo project with this...
Read more >
Heroku Error: ENOENT: no such file or directory, stat '/app ...
So, I went into my local CLI and ran heroku run bash , viewed the current files and directories, and found that /app/client/build/...
Read more >
[Solved]-ENOENT error using nodejs on heroku
Related Query · CORS error in nodejs app deployed on heroku using with angular 9 · spawn ENOENT error with NodeJS while using...
Read more >
MERN Deploy Heroku Fail
Issues attempting to deploy to heroku. ... --prefix client && npm run build --prefix client npm ERR! code ENOENT npm ERR! syscall open...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found