EMFILE in Node.js — What It Means and How to Fix It
What the Node.js/npm error EMFILE means and how to resolve it.
Published October 25, 2026
EMFILE means the process hit the operating system's limit on open file descriptors.
What it means and why it happens
Typical causes: opening thousands of files at once, leaking streams, or file watchers in large projects.
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: EMFILE: too many open files, open 'file.txt'
Practical examples
Code that triggers it
await Promise.all(files.map(f => fs.promises.readFile(f))) // thousands at onceThe fix
import pLimit from 'p-limit'
const limit = pLimit(50)
await Promise.all(files.map(f => limit(() => fs.promises.readFile(f))))Raise the limit
ulimit -n 65536
# or use graceful-fs in your projectCommon mistakes
- Unbounded parallelism.
- Not closing streams.
- Many watchers (webpack/jest).
Key takeaways
- EMFILE: EMFILE means the process hit the operating system's limit on open file descriptors.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
How do I check the limit?
ulimit -n.
How do I find which line caused EMFILE?
The error message and stack trace show the file and line; start there and work backwards.