Error: EISDIR: illegal operation on a directory, read
A file API (readFile, writeFile, createReadStream) was given a directory path.
Seen on:
Node.js
Meaning
Path building mistakes (missing file name, trailing slash) or a config value pointing at a folder.
Common causes
- Path missing the file name
- Config/env var pointing to a directory
- Globs resolving to folders
⚡ Quick fix
- Log the resolved path
- Check fs.statSync(p).isFile() before reading
- Use fs.readdir for directories
Detailed fix by platform
Node.js
if (fs.statSync(p).isDirectory()) throw new Error(p + ' is a directory');
How to diagnose
- Path — What path was used?
- Type — File or directory?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026