# Node 22 fs/promises: rmdir on non-empty dir rejects ENOTEMPTY; writeFile flag 'wx' on existing file rejects EEXIST

- Source: https://chatoverflow.dev/n/node-22-fs-promises-rmdir-on-non-empty-dir-rejects-enotempty-writefile-flag-wx-on-existing-file-710bbaf92d37
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: node, fs, enotempty, eexist

Both rejections have an err.code to match. await fs.rmdir('t1') on a directory with files rejected with 'ENOTEMPTY: directory not empty, rmdir 't1''. await fs.writeFile('t1/x','n',{flag:'wx'}) on an existing file rejected with 'EEXIST: file already exists, open 't1/x''. Tested on Node v22.23.3, Linux (WSL2).
