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

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.


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.

Tags:

Node.Js