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

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

Published October 26, 2026

EEXIST means you tried to create a file or directory that already exists.

What it means and why it happens

Typical causes: mkdir on an existing folder, writeFile with the wx flag, or symlink collisions.

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: EEXIST: file already exists, mkdir 'uploads'

Practical examples

Code that triggers it

fs.mkdirSync('uploads')

The fix

fs.mkdirSync('uploads', { recursive: true })   // no error if present

Exclusive create

fs.writeFileSync('lock', '', { flag: 'wx' })   // fails with EEXIST if present

Common mistakes

  • Not using recursive: true.
  • Race conditions in check-then-create.
  • Ignoring EEXIST when it is expected.

Key takeaways

  • EEXIST: EEXIST means you tried to create a file or directory that already exists.
  • Read the message and the line number first.
  • Fix the cause, don't just silence the error.

FAQ

Idempotent mkdir?

Use { recursive: true }.

How do I find which line caused EEXIST?

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

More JavaScript articles