Using Node.js I get, "Error: EISDIR, read"

node.js

node.js Problem Overview


When ever I try to open a file I get,

events.js:72
        throw er; // Unhandled 'error' event
Error: EISDIR, read

node.js Solutions


Solution 1 - node.js

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.

Solution 2 - node.js

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.

Solution 3 - node.js

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.

Solution 4 - node.js

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")

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEvan CarrollView Question on Stackoverflow
Solution 1 - node.jsEvan CarrollView Answer on Stackoverflow
Solution 2 - node.jsMohan DereView Answer on Stackoverflow
Solution 3 - node.jsChristofView Answer on Stackoverflow
Solution 4 - node.jsNathan ChappellView Answer on Stackoverflow