EISDIR in Node.js — What It Means and How to Fix It

What the Node.js/npm error EISDIR means and how to resolve it.

Published October 26, 2026

EISDIR means you tried to read or write a directory as if it were a file.

What it means and why it happens

Usually the path points to a folder (a variable is wrong or a trailing path is missing).

Read the full message: it names the file and line where the problem was detected, which is the best place to start.

What you see

run the code
Error: EISDIR: illegal operation on a directory, read

Practical examples

Code that triggers it

fs.readFileSync('./data')   // data is a folder

The fix

fs.readFileSync('./data/users.json', 'utf8')

List a directory instead

fs.readdirSync('./data')

Common mistakes

  • Passing a folder path to readFile.
  • Joining paths incorrectly.
  • Assuming a path is a file.

Key takeaways

  • EISDIR: EISDIR means you tried to read or write a directory as if it were a file.
  • Read the message and the line number first.
  • Fix the cause, don't just silence the error.

FAQ

How do I check?

fs.statSync(p).isDirectory().

How do I find which line caused EISDIR?

The error message and stack trace show the file and line; start there and work backwards.

More JavaScript articles