Multer error enoent no such file or directory open

ENOENT: no such file or directory .? This is error which am getting while post data and file. I have followed ‘academind’ tutorial for building Restful API services, also i have been searching answer for this type of errors but nothing works for me. Am using «multer» to upload file The folder ‘uploads’ available […]

Содержание

  1. ENOENT: no such file or directory .?
  2. 27 Answers 27
  3. ENOENT error when deploy to heroku #591
  4. Comments

ENOENT: no such file or directory .?

This is error which am getting while post data and file. I have followed ‘academind’ tutorial for building Restful API services, also i have been searching answer for this type of errors but nothing works for me.

Am using «multer» to upload file

The folder ‘uploads’ available in the folder but it shows

ENOENT: no such file or directory, open ‘D:projectuploads2018-01-24T07:41:21.832Zcheck.jpg’»

27 Answers 27

After new Date().toISOString() add replace() to change «:» to an accepted character.

Windows OS doesn’t accept files with a «:»

The person on Youtube is using MAC OS

Try the following:

    Require this as a constant (const path = require(‘path’);)

Change this line

As I can see, you are trying to get a path that is not on served on the server, but rather a path that is on the server machine.

UPDATE

Try also changing this

In order to expose the __dirname for static files.

This what worked for me. I changed ‘./uploads/’ into ‘__dirname’ so that it can find the correct directory/filename anywhere on your computer.

Because when you set a specific folder name/directory you limit your image directory to be only or should be in that folder.

So the answer is in the tutorials comments section on youtube. Instead of:

I am doing the same course and I too had the same problem (i also use windows machine). The following worked for me:

This creates a unique hash for the filenames as well

OK guys, in case someone has an issue with this in the file creation stage, that probably means you’re working on Windows. Now, you don’t need to feel discouraged and throw your computer to the trash (I actually like always having to find workarounds for my Windows :).

There’s at least a solution, and this is the one I found. My problem is the file does not get created because Windows does not accept filenames with colon (‘:’) on it. My solution is rather simple. After I get the current date, I use replace() and a regexp to change that into a dash. Viola. It works!

Hope it helps someone who´s working in windows.

I came across the same error while saving the file. The path I provided in callback didn’t exist already that’s why I got that error

With filesystem I created the same folder, In case of folder exists the err gets value but here nothing to worry about as we have that folder. This worked for me. hope this would help

Источник

ENOENT error when deploy to heroku #591

and port is set to:
var PORT = process.env.PORT || 3000;
project structure:

what did i mess up?

Thanks in advance!

The text was updated successfully, but these errors were encountered:

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:

@LinusU
my code
const storage = multer.diskStorage( <
destination : function(req,file,cb) <
cb(null,’./public/gambar/’)

>,
filename : function(req,file,cb) <
cb(null,file.fieldname + ‘-‘ + Date.now() + ‘.jpg’)
>
>)
after im upload via application
this path
http://batikmart.herokuapp.com/dashboard/product/uploads/flPhoto-1540382362434.jpg
not same with destination

so image crash and doesnt upload to path destination

@LinusU
in my app.js im set app.use(express.static(path.join(__dirname, ‘public’)));

@kukode does the folder gambar exist?

Could you change ‘./public/gambar/’ to something like this?

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.

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.

saved my day, thank u very much. but why it happen tho?

Seems like the problem is that Heroku strips empty folders. As mentioned, placing an empty file in the upload folder works around that 👍

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.

You saved my life! thank you!

Thank you so much, everyone. Empty folders were indeed the case.

I did some googling and found out that Heroku doesn’t exclude empty folders, Git does.
If you’re using GitHub along with Heroku, you can clearly see that there are no empty folders. In Heroku CLI, if you do a heroku run dir , you can see the that the empty folders are missing. The usual workaround for this is to keep a file called .gitkeep in the empty folders.

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:

This saves my day. Thank you @LinusU

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.

Thank you a million times!! It worked.

What about if i want to upload my images to heroku server ? without cloudinary or etc . ? can we do that just with heroku server ?

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:

Источник

In this tutorial, we will help you to resolve the Error: ENOENT: no such file or directory, open
'student.json'
issue.

Node.js Tutorial :

  1. Install Node.js on Windows

  2. Node.js Chalk Color Example
  3. Node.js — Read command line arguments
  4. Node.js Read Write File Example
  5. Node.js Error: ENOENT: no such file or directory

Q: What is fs module in Nodejs?
Ans:

Node.js provides an inbuilt component called FS (File System). The Node. js file system module enables
us to interact with our computer’s file system.

Error: ENOENT: no such file or directory

Error: ENOENT: no such file or directory, open 'student.json'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at Object.writeStudentData (D:nodejsfile-examplestudent-service-impl.js:24:21)
    at Object.handler (D:nodejsfile-examplestudent-app.js:10:17)
    at D:nodejsfile-examplenode_modulesyargsbuildindex.cjs:1:8891
    at j (D:nodejsfile-examplenode_modulesyargsbuildindex.cjs:1:4956)
    at M.handleValidationAndGetResult (D:nodejsfile-examplenode_modulesyargsbuildindex.cjs:1:8860)
    at M.applyMiddlewareAndGetResult (D:nodejsfile-examplenode_modulesyargsbuildindex.cjs:1:9502)
    at M.runCommand (D:nodejsfile-examplenode_modulesyargsbuildindex.cjs:1:7231)
    at Xt.[runYargsParserAndExecuteCommands] (D:nodejsfile-examplenode_modulesyargsbuildindex.cjs:1:57762) {
  errno: -4058,
  syscall: 'open',
  code: 'ENOENT',

Follow below steps to resolve Error: ENOENT: no such file or directory, open 'student.json'
issue.

  1. This problem occurs when a file does not exist; therefore, check to see if the file exists first.
  2. The suitable approach is to use fs.openSync, it
    returns the file descriptor.
  3. If the file does not exist, the w flag ensures that it is created, and if it does, it
    is overwritten
    with a new file, overriding its content.
  4. If users don’t need the file descriptor, users can close the file by wrapping the call in a
    fs.closeSync() call.
//check if file exist
if (!fs.existsSync('student.json')) {
    //create new file if not exist
    fs.closeSync(fs.openSync('student.json', 'w'));
}

Recommendation for Top Popular Post :

Nodejs Error: ENOENT: no such file or directory

This tutorial guides you on how to fix Nodejs Error: ENOENT: no such file or directory while running your node project or any application which contains Nodejs component.

Nodejs Error: ENOENT: no such file or directory

When I tried to download guacamole-client whose frontend is developed using Nodejs, and I tried to setup installing guacamole natively on Windows machine.

After downloading the code, I was trying to build guacamole-client which includes Nodejs frontend component by running “mvn package” command as shown below. But it resulted with error “Error: ENOENT: no such file or directory, open ‘C:UsersDocumentsWorkguacamole-client-masterguacamolesrcmainfrontenddistnpm-dependencies.txt’

> mvn package
---
---
[INFO] <i> [dependency-list-plugin] Skipping file dependency "srcapptextInputdirectivesguacKey.js" (no NPM package)
[INFO] <i> [dependency-list-plugin] Skipping file dependency "srcapptextInputdirectivesguacTextInput.js" (no NPM package)
[INFO] <i> [dependency-list-plugin] Skipping file dependency "srcapptextInputstylestextInput.css" (no NPM package)
[INFO] <i> [dependency-list-plugin] Skipping file dependency "srcapptextInputtextInputModule.js" (no NPM package)
[INFO] <i> [dependency-list-plugin] Skipping file dependency "srcapptouchdirectivesguacTouchDrag.js" (no NPM package)
[INFO] <i> [dependency-list-plugin] Skipping file dependency "srcapptouchdirectivesguacTouchPinch.js" (no NPM package)
[INFO] <i> [dependency-list-plugin] Skipping file dependency "srcapptouchtouchModule.js" (no NPM package)
[INFO] <i> [dependency-list-plugin] Skipping file dependency "srcindex.html" (no NPM package)
[INFO] <i> [dependency-list-plugin] Skipping file dependency "srcrelocateParameters.js" (no NPM package)
[INFO] [webpack-cli] Error: ENOENT: no such file or directory, open 'C:UsersDocumentsWorkguacamole-client-masterguacamolesrcmainfrontenddistnpm-dependencies.txt'
[INFO]     at Object.openSync (fs.js:476:3)
[INFO]     at Object.writeFileSync (fs.js:1467:35)
----
[INFO]     at AsyncSeriesHook.lazyCompileHook (C:UsersDocumentsWorkguacamole-client-masterguacamolesrcmainfrontendnode_modulestapablelibHook.js:154:20)
[INFO]     at C:UsersDocumentsWorkguacamole-client-masterguacamolesrcmainfrontendnode_moduleswebpacklibCompilation.js:1414:32 {
[INFO]   errno: -4058,
[INFO]   syscall: 'open',
[INFO]   code: 'ENOENT',
[INFO]   path: 'C:\Users\Documents\Work\guacamole-client-master\guacamole\src\main\frontend\dist\npm-dependencies.txt'
[INFO] }
[INFO] npm ERR! code ELIFECYCLE
[INFO] npm ERR! errno 2
[INFO] npm ERR! @ build: `webpack --progress`
[INFO] npm ERR! Exit status 2
[INFO] npm ERR!
[INFO] npm ERR! Failed at the @ build script.
[INFO] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[INFO]
[INFO] npm ERR! A complete log of this run can be found in:
[INFO] npm ERR!     C:UsersAppDataRoamingnpm-cache_logs21-07-28T14_42_52_884Z-debug.log

The above command “mvn package” is supposed to invoke maven to automatically build and package all the components, producing a single .war file. And while building frontend Nodejs component, it was looking for a file called “npm-depedencies.txt” but that file is missing.

Solution

As you can see from the above error, that it is expecting file called “npm-dependencies.txt” to be there in specific path. But it does not exist.

code: 'ENOENT',

path: 'C:\Users\Documents\Work\guacamole-client-master\guacamole\src\main\frontend\dist\npm-dependencies.txt'

ENOENT means Error NO ENTry (or Error NO ENTity) or simply you can say that there is NO such directory ENTry.

Therefore, you either need to create the expected file in the specific path i.e., under dist directory or else reconfigure your application so that it will point to the correct directory path for the required file.

After fixing, try building your application again. The Nodejs Error: ENOENT: no such file or directory should have gone away now.

Hope it helped 🙂

Also see:

  • Call ngOnInit() again from another function – Angular 9 ?
  • ngOnChanges get new value and previous value – Angular
  • Global Angular CLI version is greater than your local version
  • Upgrade Angular CLI to the latest version Angular 9 or 10 ?
  • How to use new static option in ViewChild Angular 9 ?
  • Project contents into angular components using ng-content
  • Call ngOnInit() again from another function – Angular 9 ?
  • ngAfterContentInit with Example – Angular
  • make npm install command to work behind proxy ?
  • Node Sass could not find a binding for your current environment
  • ngOnDestroy Example Angular
  • Angular Component : In which lifecycle hook you can check value of DOM element ?
  • @ContentChild TypeError: Cannot read property ‘nativeElement’ of undefined
  • Access ng-content with @ContentChild – Angular Component
  • How to select an element in a component template – Angular ?
  • Difference between @ViewChild and @ContentChild – Angular Example
  • Expected 0 type arguments, but got 1 : Angular
  • Angular – Access template reference variables from component class ?
  • Pass variable from parent to custom child component – Angular 9
  • Uninstall Nodejs completely from Mac OSX ?
  • EventEmitter parameter value undefined for listener
  • Typescript Error: Property does not exist on value of type
  • Remove http and https proxy settings of npm and git ?
  • How to change node version using nvm ?

References:

  • github nvm
  • nodejs docs

Recommend Projects

  • React photo

    React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo

    Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo

    Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo

    TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo

    Django

    The Web framework for perfectionists with deadlines.

  • Laravel photo

    Laravel

    A PHP framework for web artisans

  • D3 photo

    D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Visualization

    Some thing interesting about visualization, use data art

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo

    Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo

    Microsoft

    Open source projects and samples from Microsoft.

  • Google photo

    Google

    Google ❤️ Open Source for everyone.

  • Alibaba photo

    Alibaba

    Alibaba Open Source for everyone

  • D3 photo

    D3

    Data-Driven Documents codes.

  • Tencent photo

    Tencent

    China tencent open source team.

Я хочу загрузить изображение с помощью multer, но когда я меняю свой app.js, я пробовал много решений, но у меня не сработало :(

var multer = require('multer');
var path = require('path');
var id_photo = uuidv1();

global.appRoot = __dirname;

var storage = multer.diskStorage({

destination: function(req, file, callback) {
    callback(null, './uploads')
},
filename: function(req, file, callback) {
    callback(null, file.fieldname + '-' + id_photo + path.extname(file.originalname));
}
})

var upload = multer({
storage: storage,
fileFilter: function(req, file, callback) {
    var ext = path.extname(file.originalname)
    if (ext !== '.png' && ext !== '.jpg' && ext !== '.gif' && ext !== '.jpeg') {
        req.fileValidationError = "Only Image Allowed";
        return callback(null, false, req.fileValidationError)
    }
    callback(null, true)
}
}).any();

app.use(upload);
connection.init();

К

var multer = require('multer');
var path = require('path');

global.appRoot = __dirname;

var storage = multer.diskStorage({

destination: function(req, file, callback) {
    callback(null, './uploads')
},
filename: function(req, file, callback) {
    var id_photo = new Date();
    var dd = id_photo.getDate();
    var mm = id_photo.getMonth() + 1; //January is 0!
    var yyyy = id_photo.getFullYear();
    var h = id_photo.getHours();
    var i = id_photo.getMinutes();
    var s = id_photo.getSeconds();
    if (dd < 10) {
        dd = '0' + dd
    }

    if (mm < 10) {
        mm = '0' + mm
    }

    if (h < 10) {
        h = '0' + h
    }

    if (i < 10) {
        i = '0' + i
    }

    if (s < 10) {
        s = '0' + s
    }
    id_photo = mm + '-' + dd + '-' + yyyy + '-' + h + ':' + i + ':' + s;
    callback(null, id_photo + "*-" + file.originalname);

}
})

var upload = multer({
storage: storage,
}).any();

app.use(upload);
connection.init();

Я получаю такую ​​ошибку

Ошибка:

ENOENT: no such file or directory, open
‘C:Nodejsnodejs-wmcuploads4-11-2018-13:20:09*-8.jpg’
at Error (native)

Тогда как загрузка файлов уже существует, когда я использую app.js, первый работает без сбоев. что не так с моим кодом?

Пожалуйста, помогите мне … спасибо :)

Понравилась статья? Поделить с друзьями:
  • Mugen error sans
  • Mugen error detected
  • Mugen characters error
  • Mugen archive error 1020
  • Mudrunner ошибка установки