Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error ENOENT,open '/tmp/45e85388793de' in nodejs

Tags:

node.js

gridfs

I am trying to save project and its file in GridFS. I want to save project first and using "_id" of project as metadata for file I want to save file. When i tried so i am getting ENOENT, open '/tmp/45e85388793de' error. here is my code

newProject.save(function (err,project) {
            if (err) {
              console.log('save error', err);
            }
             console.log("project added");
             var id=poject._id;
             var filepath    = req.files.file.path;
             var filename    = req.files.file.name;
           var writestream = gfs.createWriteStream({ filename: filename, metadata:id });
             console.log(filepath);                                                       
             fs.createReadStream(filepath)
             .on('end', function() {

             })
            .on('error', function(err) {
             console.log("error encountered"+err);//ENOENT,open error  
             })
            .pipe(writestream);
            });

Why i am getting this error and how to resolve it?

like image 997
user3386363 Avatar asked Apr 30 '26 03:04

user3386363


1 Answers

ENOENT in this context means "No such file or directory." It means the filepath you are trying to read with createReadStream does not exist.

like image 66
yed Avatar answered May 01 '26 18:05

yed