61

When ever I try to open a file I get,

events.js:72
        throw er; // Unhandled 'error' event
Error: EISDIR, read
1
  • EISDIR = Error: it's a Directory
    – Movahhedi
    Commented Jun 25 at 8:22

5 Answers 5

96

This error is simple,

cd /tmp
mkdir dir
node -e "var fs = require('fs'); fs.createReadStream( 'dir' );"

EISDIR means that the target of the operation is a directory in reality but that the expected filetype of the target is something other than a directory.

2
  • You can select your own answer as the proper answer by the way, that's allowed by the rules. :)
    – frandroid
    Commented Jun 11, 2015 at 23:03
  • 8
    It makes me wait. As if I answered my own question wrongly and I need time to think about it. Blame Jeff. Commented Jun 16, 2015 at 16:52
16

EISDIR error occurs when you try to open a file, but the path given is a directory.

You can fix this by checking if is it directory-

if (fs.lstatSync(filePath).isDirectory()) {
  return;
}

For more reference see docs here.

4

Just came across this error and in my case it was due having used bower link previously to link to local sources which then creates a symlink in the directory. Once I've bower unlinked all the components, it worked again as expected.

Hope this might help someone.

1

You might get lucky checking for such error codes by running something like:

grep EISDIR -r /usr/include

When I do this, I get a line that says:

/usr/include/uv.h:  XX(EISDIR, "illegal operation on a directory")
1

You can see it in node.js official documentation.

import { readFile } from 'node:fs';

// macOS, Linux, and Windows
readFile('<directory>', (err, data) => {
// => [Error: EISDIR: illegal operation on a directory, read <directory>]
});

//  FreeBSD
readFile('<directory>', (err, data) => {
// => null, <data>
});

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.