Side-by-side comparison of EACCES and EEXIST — understand the differences, causes, and fixes.
The process does not have permission to access the file or resource.
The current user/process lacks read, write, or execute permissions on the file or directory. This commonly happens when running without sudo on privileged paths, or when file permissions are too restrictive.
Check file permissions with ls -la. Fix ownership with chown or permissions with chmod. Avoid running as root; instead, fix the permissions properly. On Node.js, do not use sudo npm install; fix the npm directory permissions instead.
A file creation operation failed because the target path already exists.
You tried to create a file or directory that already exists. This happens with fs.mkdirSync() without the recursive flag, or fs.writeFileSync() with exclusive flags, or fs.linkSync() when the target exists.
Check if the file exists first with fs.existsSync(). Use the { recursive: true } option for mkdirSync. Handle the EEXIST error gracefully in your catch block. Use appropriate flags (wx instead of w) only when uniqueness is required.