Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

When ever I try to open a file I get,

events.js:72
        throw er; // Unhandled 'error' event
Error: EISDIR, read
like image 531
NO WAR WITH RUSSIA Avatar asked Dec 06 '13 06:12

NO WAR WITH RUSSIA


3 Answers

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.

like image 185
NO WAR WITH RUSSIA Avatar answered Oct 08 '22 16:10

NO WAR WITH RUSSIA


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.

like image 32
Mohan Dere Avatar answered Oct 08 '22 16:10

Mohan Dere


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.

like image 4
Christof Avatar answered Oct 08 '22 16:10

Christof